Visitors Counter in PHP for your web site
I thought I needed to write this small visitors counter in PHP to display the total number of visitors in your web site. This counter is written in PHP therefore your web hosting account must have PHP enabled in order for the counter to work.
The visitors counter is made of 2 files:
- counter.txt which is a simple text file where the number of visitors is recorded and will be read from.
- counter.php is the PHP logic that takes the current number of visitors from counter.txt, increments it then write back the new value.
Most popular visitors counters I came across keep counting whenever you hit the refresh button. That does not provide an accurate measure of the number of visits to your web site but rather how many clicks and refresh are made.
Our counter relies on a much smarter logic and accurately provide the actual number of visitors. A visitor browsing through different pages is counted as 1 until s/he leaves your web site. If s/he comes back about an hour later than the counter will be incremented by 1 more visits.
You can open the counter.txt file to reset your counter to a value you would like to start counting from.
An extra file “code.html” contains the actual
The other 2 files “counter.txt” and “counter.php” have to be uploaded to your web hosting account. You should set the permissions of the “counter.txt” to enable read-write by counter.php
Feel free to contact us for technical assistance.
Download counter
Related Posts
Email This Post
| | Sphere: Related Content

March 3rd, 2008 at 12:35 pm
One more PHP counter! However this one looks serious. Good job!