Web Page Hit Counter

Web Page Hit Counter

Advert

Web Page Hit Count

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

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.

PageViews";
echo"".$row['Page']."".$;row['Count']."";
while($row=mysql_fetch_array($result))
{
echo"".$row['Page']."".$;row['Count']."";
}
echo "";
?>
To get the hits of all the page you can use this while loop to do that

while($row=mysql_fetch_array($result))
{
echo"".$row['Page']."".$;row['Count']."";
}
echo "";

Comments

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. Domain Authority

     
  2. Public Endpoint in Django Rest Framework

     
  3. 4 Ways to Increase Conversion Rates using Videos

     
  4. Getting the best customer experience analytics solutions

     
  5. How to Remove an App from Django Project

     

News Letter

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