Page 1 of 1

Need Help Translating Perl to PHP Syntax

Posted: Tue Feb 18, 2003 3:46 pm
by Solibra
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: Select all

# 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, "<count.access.log");
    @ips = <LOG>;
    close(LOG);
    foreach $_ (@ips)
    &#123;    
        if ($_ eq $userip . "\n")
        &#123;
            $firsttoday = 0;
        &#125;
    &#125;
&#125;
Furthermore i need to set the current day in a variable. in perl it would look like this:

Code: Select all

$today = (Sun, Mon, Tue, Wed, Thu, Fri, Sat, Sun)&#1111;(localtime)&#1111;6]];
            # Set to the current weekday.
How would this look in PHP?

I'd appreciate your help!

Maximilian

Posted: Tue Feb 18, 2003 5:53 pm
by lazy_yogi

Code: Select all

if (is_file("count.access.log")) &#123;
      $content_array = file("count.access.log");
      foreach ($content_array as $line) &#123;
            print $line."<BR>";
            if ($line == $userip . "\n") &#123; 
                  $firsttoday = 0; 
            &#125; 
      &#125;
&#125;

Code: Select all

$date = date ("h:i A    l dS F Y");
to see what it does

Code: Select all

print $date;
for more info :
http://www.php.net/manual/en/function.date.php

Posted: Tue Feb 18, 2003 5:58 pm
by McGruff
Hope I'm not being a smartass but would dynamic IPs give you any problems? That's not a code issue but more one of what you need to do with the yes/no test.

Posted: Tue Feb 18, 2003 6:14 pm
by Solibra
THANKS FOR TAKING THE TIME!!!

:P

Posted: Tue Feb 18, 2003 9:31 pm
by lazy_yogi
Dynamic IP's don't change that often. I *think* usually once a day
So doube that would be too much of a problem in most cases

I made a hitscounter that uses a similar thing .. but I dun think theres a better soln. for me in that regard .. and also I can live with a small bit of inaccuracy there myslef.

Can't speak for Solibra though ..... cuz I dun know what he/she needs it for.

Posted: Tue Feb 18, 2003 10:48 pm
by McGruff
I suspect they are randomly assigned from whatever is available each time you dial in - but I could be wrong.

Posted: Wed Feb 19, 2003 3:37 am
by twigletmac
AOL users seem to get a new IP address every request they make.

Mac