Many website counter sites are available now a days but still if you want to make own website counter small PHP code can work for it.
Step 1: Make a notepad file and name it “hit.txt” and write initial value of your counter. For example 0
Step 2: Upload the file to your server and give it at least 664 permission.
Step 3: Put below code in your PHP pages.
<?php $fp=fopen(“hit.txt”,”r”); $hit=fread($fp,filesize(“hit.txt”)); fclose($fp); $hit=$hit+1; $fp=fopen(“hit.txt”,”w”); fwrite($fp,$hit); fclose($fp); ?>
Step 4: Put below code where you want to display the counter.
<?php echo $hit;?>
You have done it.
Please change the file name for security reasons.Your server must support fopen function.
It is not recommended to use the code on high traffic site.It’s known issue.Because the text file gets ,multiple access and it gets rewritten many times in a second.That makes the count unpredictable and invalid or wrong value.