473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Count file

23
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.
Mar 30 '18 #1
2 4780
Luuk
1,047 Expert 1GB
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
Roamer
23
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

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

Similar topics

0
by: Marius III | last post by:
Hi there, I am building a File download counter in PHP5. It's working fine but the problem is that its not working with any Download Managers for ex: Free Download Manager / DAP etc. The...
10
by: hendafe | last post by:
I have a problem of importing a text file into Access. The text file will be imported using a delimiter, say ( , ) for example. This should be imported into the database. An example is: John,...
14
by: Sameer | last post by:
Hello, i wish to read a file of int and store into an array dynamically... the size of memory allocated finally, should just be sufficeient to store n integers. I do not know the number of...
3
by: Lars | last post by:
Hi! I´m trying to send a file over a network with tcp/ip so that the client can download it and save it. I going to send the size of the file in a textmessage but I have not implemented that...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
3
by: dru | last post by:
I am trying to read data in to a struct from a prototype My Code is: void init(student_record db,int *count) { FILE *input; char temp_str; input = fopen("mydata.txt","r");
4
by: jackloanshark | last post by:
Hello, I am a beginner of c. I wrote a program about counting words in a txt file.But actually there are some error in it and it will stop counting at the first paragraph and just return the number...
9
by: techking | last post by:
Hello ive written a program but it does not want to read from a referenced text file. i wonder if anyone can tell me what the problem is? below is the source code and after that is the text file. ...
12
by: sean kwok | last post by:
Hi, is there anyway to make the file reader read the text file dymanic? Here are the codes. <?php // Standard inclusions include("pChart/pData.class"); include("pChart/pChart.class");...
0
by: pavanijh | last post by:
i want to increment only one number in a file instead of that i am getting only string is displaying but not the number kindly help me in this ) count=0 data ="routing context count" while...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.