Visit Counter and Image Hit Counter using PHP

Hey Technoz, In this tutorials we are going to learn how to calculate page visit counter and Image Hit Counter by using PHP and MySQLi. This Visit Counter will have great impact on the websites. It enables you to see how popular your site. If visitors can see that your site is popular with others, it may encourage them to spend more time exploring the content.

Creating database

A database need to be create to store the information about page visit counter and image hit counter

So lets create the database by using following queries. The following SQL  creates counter table which consist of  id, visiters and imghit columns.

Dumping data for table ‘counter’

Note : It is important to set all values of the fields equal to zero. Why? Because to start counter value from zero.

Now lets do this task by using following query.

First, to make it convenient, we will create a new PHP file for database configuration named  dbconfig.php  that holds all configured parameters:

Code of Visit Counter

The following code index.php  is used to build user interface of Visit Counter and Image hit Counter. Also it consists of script to increment and store the Visit counter value. If visitor hit the image it redirects to the imgcounter.php .

The glimpse of the above code is shown in the following snapshot.

Visit Counter and Image Hit Counter

Code of Image Hit Counter

This code  imgcounter.php  is ignited by index.php . The job of this code is to increment the Image hit counter and redirect visitor to the index.php page. These process runs behind in visitor’s eyesight.

The glimpse of the above code is shown in following snapshot

Visit Counter and Image Hit Counter

In this tutorial we have learn to create visit counter and image hit counter and in upcoming tutorials we will learn to create unique visit counter. So make sure you have connected with us via Subscribe button.

If you have any doubts regarding to this tutorial feel free to ask in the comment section below.

To catch even more knowledgeable and easy understandable tutorials please subscribe to get email notification.

Download Source Code

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.