By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,670 Members | 1,526 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,670 IT Pros & Developers. It's quick & easy.

Count file

P: 21
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";
  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";}
  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. }
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.
Mar 30 '18 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,034
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";
Apr 2 '18 #2

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

Post your reply

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