What would a PHP code site be without a hit counter? So I am throwing in my version of this script. Using file_get_contents() for fast reading of the hits, implements a session as not to record a hit for the same user again and file locking for safe and multiple writes. Of course use as is since flock() can block the script execution if you have many visitors! For non Windows users you can use a non-blocking flock(): <pre> if (flock($fp, LOCK_EX | LOCK_NB)) </pre> and run a timed loop to wait for some milliseconds before aborting the locking. Obviously that would be an overkill of a tiny hit counter.
Its works perfectly.Thanks for the code.
You can also include it anywhere you whant, all compatible!
Neat but its not accurate. If two scripts read and the same time and bump the hits by one, each will right a hits+1 and one count will be lost. You have to read inside the flock.
I used it on my webpage for downloads count.
Thanks for the code !! =) works perfectly !