Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help Translating Perl to PHP Syntax

Status
Not open for further replies.

Solibra

Technical User
Feb 18, 2003
3
DE
Hi all!

i'm about to translate a perl script to php.

i'm stuck with the following part of the script:

it checks within a db file if the client has already accessed this page before on the current day.

Code:
# Check if user's IP is already in the daily log files.
# If it is, then set firsttoday to false (0).
if(-e "count.access.log")
{
    open(LOG, &quot;<count.access.log&quot;);
    @ips = <LOG>;
    close(LOG);
    foreach $_ (@ips)
    {    
        if ($_ eq $userip . &quot;\n&quot;)
        {
            $firsttoday = 0;
        }
    }
}

Furthermore i need to set the current day in a variable. in perl it would look like this:


Code:
$today = (Sun, Mon, Tue, Wed, Thu, Fri, Sat, Sun)[(localtime)[6]];
            # Set to the current weekday.

How would this look in PHP?

I'd appreciate your help!

Maximilian
 
Here's the answer to the second part...

$today = date(&quot;l&quot;);

That'll be Sunday,Monday,Tuesday... though...

If you really want Sun,Mon,Tue,Wed... lemme know and I'll show you.

-Rob

Check out...


for how to get more or different information from the date function.
 
This script should be functionally equivalent:

if(file_exists(&quot;count.access.log&quot;))
{
$ips = file (&quot;count.access.log&quot;);
    foreach ($ips as $ip)
    {    
        if ($ip eq $userip . &quot;\n&quot;)
        {
            $firsttoday = 0;
        }
    }
}


$today = date (&quot;D&quot;); should work in replacement for your second question. Want the best answers? Ask the best questions: TANSTAAFL!
 
i think i got it now!

thanks for taking the time guys!

Maximilian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top