How to Display number active connection in a website!
Posted: Thu Jun 26, 2003 10:31 pm
I want display number active connection in my website and write by PHP
How can I do?
Please help me!
How can I do?
Please help me!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
Create MySQL Table...
#
# Table structure for table 'useronline'
#
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)
);Code: Select all
<?php
$server = "xxx";
$db_user = "xxx";
$db_pass = "xxx";
$database = "xxx";
$timeoutseconds = 300;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
mysql_connect($server, $db_user, $db_pass);
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
if(!($result)) {
print "Useronline Select Error > ";
}
$user = mysql_num_rows($result);
mysql_close();
if($user == 1) {
print("<b>$user</b> user online\n");
} else {
print("<b>$user</b> users online\n");
}
?>