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

Posted on 21.09.2011 06:58 by vsrinivasarao

hi

Posted on 18.08.2011 18:05 by guest

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.

Posted on 02.02.2011 10:33 by guest

this is perfect

Posted on 15.01.2011 00:06 by guest

great! Thanks for this script! :D
I used it on my webpage for downloads count.
http://javildesign.com

Posted on 11.11.2010 21:49 by guest

Thanks for the code !! =) works perfectly !