## $type=slider$count=4$ico=1$cate=0$rm=0$sn=0$cm=0$show=home

Just the other day, I was asked about how to create a website counter script. Mostly the question is for PHP, so, here, instead of directing you to sophisticated scripts - especially for beginners - we'll show you how to do that in a simple and effective way starting from scratch. To solve this problem, you'll need a place to store your data - visitors no - in some place. Then when someone visit your website, just read the value form the old data and increase by 1 then display the value and replace the value in your storage place. First of all, create a file called count.dat. Open your favorite text editor and create a new PHP class for this purpose and a method to handle the data lets call this file counter.php.
So, here in this simple hitCounter class, what we have is basically a function that read the file for any old value and increment that by one then store it back. It then return the new value. Save both the count.dat and counter.php files in the same folder. Now, to use this script - say in your home page (index.php) - all you have to do is include the file and create a new instance of the class as follows:
So, now open your home page and you should see that your page increase every time you refresh it. The limitation here is that if a person view your site many times a day your site will keep increasing the value, so, you'll not get a right numbers of visitors in your website. Another limitation is that if the count.dat file is not created beforehand then this script will give an error. In the next section we'll show you how to overcome that. You can use a cookie to know if the person has visited your site before. Then also, add functionality if the data storage file exist or not? To the previous class add the following:
Here, we've added a number of hours that a person who visit the website to be considered as a new visitor. Then a cookie name is given. A cookie is a small file that is sent to the user computer and stored there. Every time a user visit the site we can access the cookie and check if it is still exist. So here, we set the time as 24 hours before our cookie expires. You can change this to any value you want. The method setHitCount() now check first if the file exist or not, if not then it create a file. Next the method check if the cookie exist or not? If cookie is not there then the function increment the value of counter and stores it in the file. As, you can see we've added a new method getHitCount() which will just retrieve the value from the file. Now, to set cookie it is always done at the beginning of a document before any HTML content is there. To do that we've created an instance of the class and call the method setHitCount();. Also, you'll need to include this file at the top of your php document. Here, is an example of how to use this class:

3/random/post-list
Name

blog,9,chemistry,7,css,1,feature,10,html,5,java-script,2,php-mysql,3,solved-qp,4,spectroscopy,3,technology,4,videos,3,web-design,13,
ltr
item
F Diengdoh.com: A Simple Website Counter Script using PHP
A Simple Website Counter Script using PHP
Create a simple website counter script using PHP.
http://2.bp.blogspot.com/-Ri3dV4cyt4Y/Vp565Cd-ieI/AAAAAAAACRs/R7g3xijNltI/s1600/slider12.jpg
http://2.bp.blogspot.com/-Ri3dV4cyt4Y/Vp565Cd-ieI/AAAAAAAACRs/R7g3xijNltI/s72-c/slider12.jpg
F Diengdoh.com
https://www.fdiengdoh.com/2016/01/a-simple-website-counter-script-using-php.html
https://www.fdiengdoh.com/
https://www.fdiengdoh.com/
https://www.fdiengdoh.com/2016/01/a-simple-website-counter-script-using-php.html
true
6372396504026100368
UTF-8