Need Help Translating Perl to PHP Syntax

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Solibra
Forum Newbie
Posts: 5
Joined: Tue Feb 18, 2003 8:27 am

Need Help Translating Perl to PHP Syntax

Post 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
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Solibra
Forum Newbie
Posts: 5
Joined: Tue Feb 18, 2003 8:27 am

Post by Solibra »

THANKS FOR TAKING THE TIME!!!

:P
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I suspect they are randomly assigned from whatever is available each time you dial in - but I could be wrong.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

AOL users seem to get a new IP address every request they make.

Mac
Post Reply