Jump to content

[SOLVED] php users online script


chris_rulez001

Recommended Posts

hi, its the same script but different problem

 

<?php
//fill in some basic info
$server = "localhost";
$db_user = "";
$db_pass = "";
$database = "chrisrulez_usersonline";
$timeoutseconds = 300;

//get the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

//connect to database
mysql_connect($server, $db_user, $db_pass);

//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}')");
if(!($insert)) {
    print "Useronline Insert Failed > ";
}

//delete values when they leave
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE $timestamp<$timeout");
if(!($delete)) {
   print "Useronline Delete Failed > ";
}

//grab the results
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'");
if(!($result)) {
   print "Useronline Select Error > ";
}

//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");
}
?>

 

//delete values when they leave

$delete = mysql_db_query($database, "DELETE FROM useronline WHERE $timestamp<$timeout");

if(!($delete)) {

print "Useronline Delete Failed > ";

 

^ that bit is causing the problem, i think.

 

with the problem the script shows:

 

Useronline Delete Failed > 1 user online

 

i would like it just to show:

 

1 user online

Link to comment
https://forums.phpfreaks.com/topic/51108-solved-php-users-online-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.