Build a Simple Hit Counter With PHP
Here is a quick text-based solution to have a simple hit counter on a single page. This is not meant to provide any sort of advanced web analytics, merely a count of how many times a web page has been loaded.
Create an empty text file in the same directory as the PHP page that you want to count hits on. Call it whatever you want. You could duplicate this counter accross pages, just create a unique text file for each page you want to track.
The function gets the text file, opens it for reading and writing, saves its contents, closes it, opens it again, adds 1 to the total count, displays the hit count and then finally saves and closes the file again.

on December 12th, 2006 at 8:28 pm
Hey Justin, I love this code. Very simple and effective. Quick question; is it possible to set this to reset itself every 24 hours, or at a set interval? Thanks. =)
on January 22nd, 2007 at 10:31 am
Hey thanks for the script. I was looking for awhile before I found one that worked. I had some trouble using a mysql one because my host is crap so this simple really hit the spot. Thanks!
on September 7th, 2007 at 10:57 pm
Hi,
Thanks for the smart little piece of code. I needed something in a hurry with minimum overhead and it was on the server and working in three minutes. No even any CHMODing. My boss in impressed!
Thanks,
Dan
on October 11th, 2007 at 11:08 am
I have typed the website name in the website field.
I am having trouble making the PHP function work on the website as I have little knowledge of PHP, any chance you could give me some help via email to how to sort my problem out?
on July 27th, 2008 at 10:20 pm
Hey,How can I output the daily hits in a table type..I want to retrieve the data and see from the start of the month until the present day.
thanks for any help
on October 14th, 2008 at 9:06 pm
I tried it but after a few thousand hits, the counter would reset itself… hmmm…