PHP simple : PHP tutorial, MySQL tutorial
PHP Tutorial - Free PHP Script

Home | Tutorials | Php vs Node.Js | Web Tools

Real Visitor Counter


Tutorials > Real Visitor Counter

By the simple counters (easy counter & easy counter with images tutorials), when you refresh which page again and again the counter plus by 1 everytime. Only you can make more than 1,000 visitors in minute (the truth is you; 1 person). Not good for use them in your real sites.

This tutorial will show you how to make a simple real visitor counter. It's mean that when someone comes and browse your site or refresh your pages many times. It's still count at 1 (1 person) until he leaves (close his browser).

Overview

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

  1. real_visitor_counter.php
  2. Database "tutorial" and table "easy_counter" with 1 fields: visitor(Int, 11). You need to insert a first one record with "0".


easy_counter.php

Source Code
<?
// For using session variables put this function on the top.
session_start();

// Connect database
mysql_connect("localhost","","");
mysql_select_db("tutorial");

/* Check for session variable "visitor".
If not exist, update database and create this session by Session ID.*/

if(!session_is_registered("visitor")){
$visitor=session_id();
session_register("visitor");

// Update value in column "all_visitor" by +1.
mysql_query("update easy_counter set all_visitor=all_visitor+'1'");
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
Counter :
<?
// Select data from easy_counter and put them into $result.
$result=mysql_query("select * from easy_counter");
$row=mysql_fetch_assoc($result);

// Output all_visitor record.
echo $row['all_visitor'];

// Close database connection.
mysql_close();
?>

</body>
</html>


Advertise
Put Ebay RSS Feeds onto your website
SEO Elite Software
Domain Dashboard CPanel & Seo Manager
Work at Home Ideas and Opportunities
Introduction & Get Start
Using Form
PHP
PHP Tags
PHP Variables
PHP Control Structures
MySQL
Create Database & Table
Database Connection
Insert Record
Select Record
Update Record
Delete Record

PHPsimple.net
info@phpsimple.net