naitsirhc26

msg:3706603 | 7:14 pm on Jul 24, 2008 (gmt 0) |
This is what I've got so far. For some reason it won't increase the number in hits.txt by one. Any thoughts? (I'll work on saving/clearing the data nightly later.) -------------------- <?php $hits = file_get_contents("hits.txt"); $hits = $hits + 1; $handle = fopen("hits.txt", "w"); fwrite($handle, $hits); fclose($handle); echo $hits; ?>
|
MattAU

msg:3706748 | 10:25 pm on Jul 24, 2008 (gmt 0) |
That looks ok to me. Are the any errors? If you're using Linux/BSD you'll probably need to chmod hits.txt to 666. If that doesn't help put error_reporting(E_ALL); at the top of the script to make sure there are no other errors. You could also try typecasting $hits (see below), but that shouldn't be the issue in PHP. $hits = (int)file_get_contents("hits.txt");
|
dreamcatcher

msg:3707305 | 2:37 pm on Jul 25, 2008 (gmt 0) |
Shouldn`t you need to clear the original file before writing the new one? dc
|
CDNQuilter

msg:3707337 | 3:03 pm on Jul 25, 2008 (gmt 0) |
If you had an earlier bug that wrote something invalid to your file, then adding 1 to that invalid value will just produce another invalid value. Try deleting the file and letting your script create it afresh. As far as the midnight roll up is concerned, if it is important that it be done right at midnight then you will need a cron job. Otherwise, you could add a comma and a timestamp to your file and check the timestamp every time you increment the counter. If the date has changed by one day, then you report the old number somewhere and start again from 1. cheers j
|
|