PHP Hit Counter

A small but not that simple hit counter.


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

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.



Posted on 16.04.2014 20:59 by guest

finally, it helps me out.. :)

Posted on 13.04.2013 11:12 by guest

thank u...

Posted on 24.02.2013 22:40 by guest

Thanks! This is the best way to do it with a simple file as database and
You can also include it anywhere you whant, all compatible!
Ipressive! Love it! :)

Posted on 28.12.2012 09:16 by guest

thank you very much.....

Posted on 22.09.2012 03:04 by guest


Posted on 05.09.2012 14:35 by guest

where I keep this php file and how to use this php file or may i use only code in my index html file? jst wanna only a beginner. thanks a lot...

Posted on 25.05.2012 08:04 by guest

Thank You.... The most best counter script ever... Thanks again....

Posted on 10.05.2012 11:11 by guest

thank you

Posted on 13.02.2012 08:23 by guest

Thanks for your information. This is helpful for my work. Again thanks. by mdrayhankhan

Posted on 12.02.2012 13:33 by guest


Posted on 21.09.2011 04:58 by vsrinivasarao


Posted on 18.08.2011 16: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 09:33 by guest

this is perfect

Posted on 14.01.2011 23:06 by guest

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

Posted on 11.11.2010 20:49 by guest

Thanks for the code !! =) works perfectly !