I was wondering if there was a way to have this counter clear after 24 hours. I want to put 2 counters on my site. 1 being an all time unique visitor counter (which this will do) and another to count unique visitors for the day. <?php $filename = "hits.txt"; $file = file($filename); $file = array_unique($file); $hits = count($file); echo $hits; $fd = fopen ($filename , "r"); $fstring = fread ($fd , filesize ($filename)); fclose($fd); $fd = fopen ($filename , "w"); $fcounted = $fstring."\n".getenv("REMOTE_ADDR"); $fout= fwrite ($fd , $fcounted ); fclose($fd); ?> Code (markup):
write a php script for remove hits.txt ( php.net/unlink ) and this script must create hits.txt after delete. lastly add cronjob to 00:00 from your control panel.
One suggestion might be to check the file creation time before writing to the file, if that is one or more days ahead of the servers current time then delete the record file and make a new one. This would only work on a Windows server though, seeing as *nix does not store creation timestamps. To check the creation time on a file check out: http://us.php.net/manual/en/function.filectime.php (Again if your using a *nix server this function will return the last time it was changed, if your on windows it will get the creation time.) You could also set a cron job to do it, if your host allows it.