PHP Hit Counter
A small but not that simple hit counter.
Usage
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():
if (flock($fp, LOCK_EX | LOCK_NB))
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.


Comments
hi
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.
this is perfect
great! Thanks for this script! :D
I used it on my webpage for downloads count.
http://javildesign.com
Thanks for the code !! =) works perfectly !