chris_rulez001 Posted May 12, 2007 Share Posted May 12, 2007 hi im a newbie at php, can i have some help with my users online script? please <?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','$REMOTE_ADDR','$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='$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"); } ?> Problems Ocurring: Notice: Undefined variable: REMOTE_ADDR in /www/1111mb.com/c/h/r/chrisrulez/htdocs/whos_online.php on line 18 Notice: Undefined variable: PHP_SELF in /www/1111mb.com/c/h/r/chrisrulez/htdocs/whos_online.php on line 18 Useronline Delete Failed > Notice: Undefined variable: PHP_SELF in /www/1111mb.com/c/h/r/chrisrulez/htdocs/whos_online.php on line 30 Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/ Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 change $insert = mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); to $insert = mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}')"); and $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); to $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'"); Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/#findComment-251569 Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 try to change $REMOTE_ADDR and $PHP_SELF into $_SERVER['REMOTE_ADDR'] and $_SERVER['PHP_SELF'] Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/#findComment-251571 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 or at the top add: $REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; $PHP_SELF = $_SERVER['PHP_SELF']; their 2 options Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/#findComment-251574 Share on other sites More sharing options...
chris_rulez001 Posted May 12, 2007 Author Share Posted May 12, 2007 cheers for your help Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/#findComment-251576 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 Oh can you please click solved (bottom left) Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/#findComment-251578 Share on other sites More sharing options...
chris_rulez001 Posted May 12, 2007 Author Share Posted May 12, 2007 i have clicked it Link to comment https://forums.phpfreaks.com/topic/51107-solved-users-online-problem/#findComment-251580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.