This option will reset the home page of this site. Restoring any closed widgets or categories.

Reset

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.5.7_846]
Rating: 0.0/10 (0 votes cast)
VN:F [1.5.7_846]
Rating: +1 (from 1 vote)

Related posts:

  1. Simple Pagination Using PHP Script
  2. Export MySQL to CSV (Excel) using php
  3. Hit counter using php
  4. Total Number Of Rows In MYSQL
  5. How to get the IP address of the visitor with PHP?
  6. Send Email to Multiple Persons using php
  7. Simple PHP Login Script

Leave a Reply

Comments (required)

Spam Protected