
You may want a hit counter on your site, this can be done through some very simply lines of code.
The first thing you need to do is create a file called hits.txt
Once this has been created just close it, we won’t need to do anything with it. The next thing we need to do is create a PHP file. Call it what ever you want, it doesn’t matter in this case.
Then we can start coding…
The first bit of code to add to your PHP file is:
$hits = file_get_contents('hits.txt');
What this does it gets the number of hits from the hits.txt file. Then add…
$hits += 1
What this does is adds 1 to the number of hits.
file_put_contents('hits.txt', $hits);
Then this bit of code puts that into hits.txt
This next bit is optional, you can echo the number of hits you have on that page. You do this by the following bit of code…
echo $hits;
Then you will need to set the permissions of hits.txt to 777
Then thats it. Short and sweet ;)






































October 4th, 2008 at 1:21 am
Very simple, a good tutorial for beginners. Though, I do think that it should be expanded on. Then again, it’s a hit counter and not a statistics tracker.
October 4th, 2008 at 2:06 am
Yes, I was going to expand. Mabey make it into a stat counter. Something like Statcounter. Where the user would add an image or something then they could track stats and things. But it gets quite hard to track alot of things past pageloads and unique views.
November 7th, 2008 at 5:30 am
Thursday In searching for sites related to AdSense but more specifically to %KEYWORD, I found your site which has great content.
November 25th, 2008 at 3:47 pm
Could you please translate this PHP tutorial so I can use it on my flash-made site? I used action script 2.0, I have not yet learned 3.0, I admit with embarrassment.
Thank you,
Cornelia