Last updated on January 30th, 2022 at 07:42 pm

This tutorial require 1 PHP file and 1 table of mySQL database.

1. counter.php
2. Database “mypage” and table “counter” with 1 fields: visitor(Int, 11). You need to insert a first one record with “0”.

You might also be interested in

1] Hit Counter using PHP and Text File (With Demo / Any PHP Version)

2] Image hit counter using PHP/MySQL (With Demo / PHP 5 and Above)

Source Code (Only compatible with PHP 5 or lower version)

// For using session variables put this function on the top.
// Connect database
/* Check for session variable "visitor".
If not exist, update database and create this session by Session ID.*/
// Update value in column "all_visitor" by +1.
mysql_query("update counter set visitors=visitors+'1'");
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Counter :
// Select data from easy_counter and put them into $result.
$result=mysql_query("select * from counter");
// Output all_visitor record.
echo $row['visitors'];
// Close database connection.

2 thoughts on “Simple Visitor Counter Using php”
  1. omg, you tell me to create a table ‘counter’ with one column ‘visitor’
    but your query set visitorS=visitorS+’1′ :\
    thanks for your help though

Leave a Reply

Your email address will not be published. Required fields are marked *