Web Page Hit Counter

Web Page Hit Counter


Web Page Hit Count

In this tutorial we'll create a counter that will count no of views.

You can make your own Web Page Hit Counter using Mysql and PHP or just by PHP alone for a single page.This cannot be used for sites with multiple pages because every time the page loads it counts as new visit.
But you can make different tables for diffrent pages.For sites with myltiple pages check the multiple page counter from projects.

PHP version

no of visit--

Then the trim() function is used to remove any new line characters so we have an integer
This stores the no of visit in a text file named counter.txt you can change to your desired name.
You can have different files for different pages to use for multiple pages.

PHP and Mysql version

First of all create a database and call it Counter, also create a table in that database with 2 fields, 'Page' which as a 20 character (or more) varcharacter format and 'Count' which has an intermediate integer format.
Insert rows equal to the number of pages on your site, and enter 'Count' as zero.
At every page insert the following code:

This counts the visit and increments value to the variable in the table with corresponding page.
To display the hits put this code where ever you want.

echo "";
To get the hits of all the page you can use this while loop to do that

echo "";


Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ rel="nofollow" for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.

Last 5 Articles

All Articles >

  1. Ten Tips for Effective Work in Web Design

  2. Security Myths

  3. Model Design for Orders in Django

  4. Automating Business Operations

  5. Unit Testing in Python using assertAlmostEqual


News Letter

Subscribe to our email newsletter for useful tips and valuable resources, sent out every new article release.