PHP

Hit counter in PHP

First create a page hitcounter.txt save in the same directory  you will put your hit counter in. put the value in hitcounter.txt where you want to  start your hitcounter .

1.Set the variable to file hitcounter.txt. Set the number of visits to the current value of the contents of the hitcounter.txt file:

2. When the script is accessed as the page loads, it not only reads the current number of hits on the page in the hitcounter.txt, it must increase the value by 1 for the current hit to be recorded. Add 1 to your value of $hits and call it $hits

3. Open the file that is keeping count so we can write to it

4.Replace the value in the file with the new $hits number after it was incremented.

5.Close the txt file.

6.Set the code to display your hit number.

View Demo

Download Source Code(Hit counter in PHP)
Size: 596 Byte
Version: V 1.0

About the author

Anuj kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Leave a Comment