Users online - on your site

You must have seen this on some sites where they display the number of users online. This scripts exactly does that. It displays number of users currently browsing your website.

The table structure

Code:

CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
file varchar(100) NOT NULL,
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY file (file)
);

User’s Online Displays the numbers of users on your website at any one time.

Code:

<?php
$server = "xxx";
$db_user = "xxx";
$db_pass = "xxx";
$database = "xxx";

$db = mysql_connect($server, $db_user,$db_pass);
mysql_select_db($database,$db);

$timeoutseconds = 300; //5 minutes

$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

$insert = mysql_query("INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')",$db);
if(!($insert)) {
print "Useronline Insert Failed > ";
}
$delete = mysql_query("DELETE FROM useronline WHERE timestamp<$timeout",$db);
if(!($delete)) {
print "Useronline Delete Failed > ";
}
$result = mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'",$db);
if(!($result)) {
print "Useronline Select Error > ";
}
$user = mysql_num_rows($result);

mysql_close();
if($user == 1) {
print("$user user online\n");
} else {
print("$user users online\n");
}
?>
m121ban2





mp

Star Resell Our Services As Your Own
Basic Reseller
Pro Reseller
Reseller Login

register domain names
Domain Sales
.com $8.99 (Now-Sept)

dotme
NEW .ME
There’s a story inside each one of us, waiting to be told. Tell yours to the world with .ME -- the Top Level Domain that’s all about you!