ode:
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) );
PHP Code:
$server = "localhost"; $db_user = "root"; $db_pass = ""; $database = "online";
$timeoutseconds = 1000; $timestamp=time(); $timeout=$timestamp-$timeoutseconds; mysql_connect($server, $db_user, $db_pass) or die ("Useronline Database CONNECT Error"); mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("Useronline Database INSERT Error"); mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout") or die("Useronline Database DELETE Error"); $result=mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'") or die("Useronline Database SELECT Error"); $user =mysql_num_rows($result); mysql_close();
if ($user==1) {
echo"online: $user user";
}
else
{
echo"online: $user users";}
?>
PHP Code:
include("useronline.php"); ?>
No comments:
Post a Comment