Facebook Twitter Reset

This Tutorial Has Been Viewed 6,772 Times.

Simple Visitor Counter Using php

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″.

Counter.php
Source Code

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

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

/* 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 counter set visitors=visitors+'1'");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Counter</title>
</head>
<body>
Counter :
< ?
// Select data from easy_counter and put them into $result.
$result=mysql_query("select * from counter");
$row=mysql_fetch_assoc($result);

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

// Close database connection.
mysql_close();
?>
</body>
</html>

VN:F [1.9.13_1145]
Rating: 8.2/10 (13 votes cast)
VN:F [1.9.13_1145]
Rating: +3 (from 5 votes)
Simple Visitor Counter Using php, 8.2 out of 10 based on 13 ratings

Incoming search terms:




You will also be interested in ,

One Response to “Simple Visitor Counter Using php”

  1. July 2, 2011 at 4:26 am #

    thank you very much….
    your good..

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: +1 (from 1 vote)

Leave a Comment

Spam protection by WP Captcha-Free

Affordable Seo PackagesSeo BlogEdu Backlinks
More in PHP, scripts (112 of 149 articles)