RE: [PHP-WIN] User Online

From: Date: Thu, 24 Jun 2004 17:36:09 +0000
Subject: RE: [PHP-WIN] User Online
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-24065@lists.php.net to get a copy of this message
Could anyone help me to correct user online code: I am stuck in this point... CREATE TABLE useronline ( timestamp int(15) NOT NULL default '0', ip varchar(40) NOT NULL default '', file varchar(100) NOT NULL default '', PRIMARY KEY (timestamp), KEY ip (ip), KEY file (file) ) TYPE=MyISAM; <?php $host = "localhost"; $db_user = "socheat"; $db_pass = "socheat"; $db_name = "ppdirectory"; $timeoutseconds=300; //get the time $timestamp = time(); $timeout = $timestamp-$timeoutseconds; //connect to database mysql_connect($host, $db_user, $db_pass); //insert the values mysql_db_query("$db_name", "INSERT INTO useronline VALUES('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); print("INSERT INTO useronline VALUES('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); //delete values when they leave mysql_db_query($db_name, "DELETE FROM useronline WHERE timestamp<$timeout"); //grab the results $result = mysql_db_query($db_name, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); //number of rows = the number of people online $user = mysql_num_rows($result); //spit out the results mysql_close(); if($user == 1) { print("$user user online\n"); } else { print("$user users online\n"); } ?>

« previous php.windows (#24065) next »