Website stats counter with PHP,MySQL and JavaScript

counterThis tutorial will explain how to create a simple page view counter or website views counter using PHP,MySQL and  JavaScript .In this tutorial I am using Java Script although it can be done without JavaScript.Reason for using JavaScript is that it will also count the page view if visitor visits a cache page and you can also host these files on another server to save resources.

Files:

1.config.php -To store your database configuration .

2.stats.php – To save and retrieve number of visitors.

3.visits.sql - To import structure of a table.

How to use -

1.Import the visits.sql  using PHPMyAdmin.

2.Change the  file config.php (given in step 2).

3.Upload the file config.php and stats.php to your server.

4.Replace the value of src attributed with location of your stats.php file and paste this code where  you want to show the statistics.

Here is the detail description for creating website stats counter with PHP,MySQL and JavaScript.

1).In first line of given code, an empty division is created  where stats of your website like total page view will display.I have used a division which webstats ID,if you want to change this ID then make sure to change in the stats.php too.

webstats”>

You can replace the source of Java Script file with your own.You just need to paste this code on the pages where you want to display the statistics.

2).cofig.php – This file is store configuration of your MySQL database .

 3).stats.php – This file with return a java script code which will replace the content of webstats division with website stats.

Customisation: Above script will only show the total page view of a website ,but changing few lines you can show more stats like Current Page Views ,Online Users,Today’s view etc.See how to do these things.

1).Show page view of current page -

Replace Line -15 with given code in stats.php.

 2).Show number of online users -

Replace Line -15 with given code in stats.php.

 3).Show today’s page views -

Replace Line -15 with given code in stats.php.

Demo Download Source

Incoming Search Terms:

  • how to make website counter in java script
  • mysql jquery online counter
  • php mysql using counter to echo a text after an interval of time
  • statistics php mysql
  • Soelay

    Oh That is a nice for web developer!

  • Guest

    Excellent! Thanks! Keep up the blogging!

  • http://www.theidiotspace.blogspot.com/ King_Hermy

    Nice, thanks, keep up the blogging.