422,363 Members | 2,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,363 IT Pros & Developers. It's quick & easy.

Count file

P: 19
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.

Expand|Select|Wrap|Line Numbers
  1. $pagelog="visits.txt";
  2.  
  3. ($sec,$min,$hour,$mday,$mon,$year) = gmtime();
  4. $year = $year + 1900; $mon = $mon + 1;
  5. if ($mon<10) {$mon="0$mon";}
  6. if ($mday<10) {$mday="0$mday";}
  7.  
  8. if ($mday == 01)
  9.  {print qq~<b>$mday</b>~;
  10.  open VN, ">$pagelog"; close VN;}
  11.  else {
  12. print qq~<b>Log the next visitor</b>~;
  13. }
  14.  
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.
3 Weeks Ago #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 909
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):
Expand|Select|Wrap|Line Numbers
  1. $pagelog="visits"+$mon+$year+".txt";
3 Weeks Ago #2

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

Post your reply

Sign in to post your reply or Sign up for a free account.