Create website Visitor Hit Click Pageviews counter in PHP script example tutorial

How to make your own hit counter script for my website using PHP and display click on screen in numeric digit.

Hit counter is one of the most useful thing for websites because it helps the website owner to detect amount of clicks on its website/blog. There are lot’s of hit counter scripts available online freely and some of website gives you simple one line code to detect the page-views. But some times using their code on your own website might generate some kind of error on your web page. So for all the developers who really trying to make hit counter for their website without putting another website’s script inside there web page. Here is the complete step by step tutorial for Create website Visitor Hit Click Pageviews counter in PHP script.

android-project-download-code-button

Note : This script is free for both professional and personal use. You can download and use it any place without my permission.For any help to integrate this into your website please comment below.

How to Create website Visitor Hit Click Pageviews counter in PHP script.

Note : Please create visitor-hit-counter.txt named text file and put the text file as same folder where you have placed our hit-counter.php file.

Code for index.php file.

 <?php include 'hit-counter.php' ?> 
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Visitor Hit Counter</title>
<style>

body{
 margin:0px;
 }

.home{
 width: 500px;
 height:200px;
 border-radius: 5px;
 border: 1px solid #ccc;
 background-color:#E3F8F9;
 }
.counter{
 
 width:100px;
 height:20px;
 border-radius: 5px;
 border: 1px solid #ccc;
 padding: 14px 14px 14px 14px; 
 background-color:#A02325;
 font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
 font-size:22px;
 color:#FBF7F7;
 margin-top:65px;
 float:left;
 
 }
 
.sampleText{
 
 font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
 font-size:22px;
 color:#A02325;
 margin-top:80px;
 float:left;
 margin-left:70px;
 margin-right:20px;
 
 }
</style>

</head>

<body>
<center>
<div class="home">

<div class="sampleText"> Hits on Website = </div>
<div class="counter"> <?php HitCounter(); ?> </div>

</div>
</center>
</body>
</html>

Code for hit-counter.php file.

<?php

function HitCounter()
{
 
$TextFile = fopen("visitor-hit-counter.txt", "r");
 
 $HitValue = (int) fread ($TextFile,20) ;
 
 fclose ($TextFile) ;
 
 $HitValue++ ;
 
 echo $HitValue ;
 
$TextFile = fopen("visitor-hit-counter.txt", "w" ) ;

fwrite($TextFile,$HitValue) ;

fclose ($TextFile) ;

 }


?>

Screenshot:

Create website Visitor Hit Click Pageviews counter in PHP script

Click here to download Create website Visitor Hit Click Pageviews counter in PHP script project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *