Php tutorial: How To Create A Simple Hit Counter for your site

Most webmasters and wapmasters do think creating a hit counter has to be complex and database driven. But am going to explain how to create a simple hit counter that is accurate and easy without worry about creating a database.
How do i create a simple hit counter?
.1. Create a .txt file e.g name hitcounter.txt at the base or root folder of your site or page u wana use the counter
.2. Create another file named eg counter.php and put this lines of code.
< ?php $count_my_page = ("hitcounter.txt"); $hits=file($count_my_page); $hits[0] ++; $fp = fopen($count_my_page , "w"); fputs($fp, "$hits[0]"); fclose($fp); echo $hits[0]; ?>
.3. To display the number of hit, use php include or require function to declare it. I.e put <?php include(‘counter.php’); ?> or <?php require(‘counter.php’); > anywhere you want to display the counter.

Alternative Method On How to Create a Hit Counter

after step 1, use the code, i.e
< ?php $count_my_page = ("hitcounter.txt"); $hits=file($count_my_page); $hits[0] ++; $fp = fopen($count_my_page , "w"); fputs($fp, "$hits[0]"); fclose($fp); echo $hits[0]; ?>
to display the hit anywhere in your site or page without using php include or require function.
Web Hosting