Page 1 of 1

Problem With Showing Registered Users Online..

Posted: Fri Dec 30, 2005 3:37 pm
by saqib389
this code is always showing me...... like this

People Online:
Guests Online: 0
Members Online: 0


i m online in my site.. and registered users are also online.. but still its showing this output in this code
please any one can help me




Code: Select all

<?

$dbhost = 'localhost'; 
$dbusername = ''; 
$dbpasswd = ''; 
$database_name = 'l'; 

#under here, don't touch! 
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd") 
    or die ("Couldn't connect to server."); 
$db = mysql_select_db("$database_name", $connection) 
    or die("Couldn't select database."); 




if(!session_is_registered('userid')){ 
    @mysql_query("INSERT INTO ppl_online (session_id, activity, ip_address, refurl, user_agent) <br>        VALUES ('".session_id()."', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGENT']}')"); 
    session_register('userid'); 
} else { 
    if(session_is_registered('userid')){ 
        @mysql_query("UPDATE ppl_online SET activity=now(), member='y' WHERE session_id='".session_id()."'"); 
    } 
} 
if(session_is_registered('userid')){         
    @mysql_query("UPDATE ppl_online SET activity=now() WHERE session_id='".session_id()."'"); 
} 




// This file is included into your website 
// Preferably a MySQL connection has been established already 

$limit_time = time() - 300; // 5 Minute time out. 60 * 5 = 300 
$sql = mysql_query("SELECT * FROM ppl_online WHERE UNIX_TIMESTAMP(activity) >= $limit_time AND member='n' GROUP BY ip_address") or die (mysql_error()); 
$sql_member = mysql_query("SELECT * FROM ppl_online WHERE UNIX_TIMESTAMP(activity) >= $limit_time AND member='y' GROUP BY ip_address") or die (mysql_error()); 
$visits = mysql_num_rows($sql); 
$members = mysql_num_rows($sql_member); 

echo "People Online:<br />"; 
echo "Guests Online: $visits<br />"; 
echo "Members Online: $members<br />"; 

// Database connection information here 

$maxtime = time() -600; 
$sql = mysql_query("DELETE FROM ppl_online WHERE UNIX_TIMESTAMP(activity) < '$maxtime'"); 
$rows = mysql_affected_rows(); 

echo "Total of $rows Deleted"; 

?>

Posted: Fri Dec 30, 2005 3:47 pm
by Charles256
remove all that error supression "@" and see if you get something to pop up :-D

Posted: Sat Dec 31, 2005 7:05 pm
by saqib389
error is still same
please helppppppppppppppppppp
:( :(

Posted: Sat Dec 31, 2005 9:22 pm
by Burrito
take a look at this line:

Code: Select all

@mysql_query("INSERT INTO ppl_online (session_id, activity, ip_address, refurl, user_agent) <br>        VALUES ('".session_id()."', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGENT']}')");

Posted: Sun Jan 01, 2006 8:38 am
by saqib389
same thing...... same error.......

please guyz do some thing for this

Posted: Sun Jan 01, 2006 11:33 am
by John Cartwright
Were not here to write code for you my friend, we are more geared to making suggestions and letting you figure it out for yourself. Here are some tips that you could try

1) Post new code revisions after each suggestions, so were all on the same page, and we can make sure you did it correctly
2) Add debugging echo's throughout your script to see if the flow of the script goes where you expect it to.. for example

Code: Select all

if(!session_is_registered('userid')){
    echo 'got to point 1';
    mysql_query("INSERT INTO ppl_online (session_id, activity, ip_address, refurl, user_agent) <br>        VALUES ('".session_id()."', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGENT']}')") or die(mysql_error());
    session_register('userid');
} else {
    echo 'got to point 2';
    if(session_is_registered('userid')){
         echo 'got to point 3';
         mysql_query("UPDATE ppl_online SET activity=now(), member='y' WHERE session_id='".session_id()."'") or die(mysql_error());
    }
}
3) Now supressing errors in this situation is bad. You should also add

Code: Select all

or die(mysql_error();
to all your queries to determine what would go wrong.. notice that you have a <br> in your query, which I posted above



That should get you started.