Visitors counter script is just simple way to counts how much time your web page has been accessed. Through this you can show the world that how many visitors you got. Its very fascinated to show on web page and also encourage the visitors too.
In this post i will explain you how to add a basic visitors counter on website in PHP. Its quite easy and implement using few PHP code lines.
PHP Visitor Counter Code for Website:
For this script you need two files one is hitcount.txt file and another count.php file.
Now write down the count.php file code to count the number of visitors of your webpage.
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $count_page = ("hitcount.txt"); $hits = file($count_page); $hits[0] ++; $fp = fopen($count_page , "w"); fputs($fp , "$hits[0]"); fclose($fp); echo $hits[0]; ?> |
Save the digit 0 in hitcount.txt file and must placed this file along with count.php file on same directory.
To use this script code on your web page, you just add a php code line on your web page.
<?php include(‘count.php’); ?>
After doing this whenever your web page load, count number store in hitcount.txt file and showing on your webpage. Hope this post will help you to create an visitors count four your website.
Wow it works
Thanks. Very simple and precise.