Count file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Roamer
    New Member
    • Dec 2012
    • 23

    Count file

    Hi, I have a file which counts the actual visits to my site pages (not a hit counter).

    It works fine, but I have to manually wipe it each month.

    Is there an easy way (without modules) to zero out the file on the first day of the month 01 ($mday) only once! Which means it has to ignore the $mday of 01 after the first time. I can zero the file okay, but from there is beyond my skill.

    Then every visit to a page is added as normal until the next month 02 ($mday) and repeats it. Without a cron job.

    Code:
    $pagelog="visits.txt";
    
    ($sec,$min,$hour,$mday,$mon,$year) = gmtime();
    $year = $year + 1900; $mon = $mon + 1;
    if ($mon<10) {$mon="0$mon";}
    if ($mday<10) {$mday="0$mday";}
    
    if ($mday == 01)
     {print qq~<b>$mday</b>~;
     open VN, ">$pagelog"; close VN;}
     else {
    print qq~<b>Log the next visitor</b>~;
    }
    At the moment it will just keep overwriting the file, which is not what I want it to do.

    Or am I approaching this the wrong way?

    Thanks in advance for any help.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    You could rename the file from 'visits.txt' to 'visitsMMYY.txt ', where MMYY should be replace by the current month and year.

    So, move line#1 to line7 and change it to (untested):
    Code:
    $pagelog="visits"+$mon+$year+".txt";

    Comment

    • Roamer
      New Member
      • Dec 2012
      • 23

      #3
      Thanks Luuk, I'll give that a try. Dunno why I didn't think of that in the first place. Just needs another conditional.

      Comment

      Working...