MySQL Hit Counter

Printer-friendly versionPDF version
Your rating: None Average: 4 (2 votes)

It is simple php hit counter that uses MySQL database to store count logs. It can count hits for all the pages of your site.

Features

  • PHP based hit counter
  • Uses MySQL as database
  • Can count hits for multiple pages

Installation:

  1. Open counter.php with notepad and put your database hostname, username, password and database name correctly.
  2. Upload the counter.php file in to your server.
  3. Log in to your database with phpmyadmin and execute this query
    CREATE TABLE `mysql_couter_logs` (
    `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `name` TEXT NOT NULL ,
    `hits` INT NOT NULL DEFAULT '0'
    )
    	
  4. To add a page on database for counting logs log in to your database with phpmyadmin, click on Insert from the top menu of phpMyAdmin. Give a page name, no need to give id or hits, leave them blank.
  5. To add more pages repeat step 4 as many time as you need.

Counting and showing hits
Add the script below in you homepage where you want to show your hit counts. Don't forget to check the correct url to counter.php

<SCRIPT LANGUAGE="Javascript" SRC="counter.php?page=pagename"><!--//--></SCRIPT>

Change the pagename with current page name you provided on database.

Source Files: