Problem With Showing Registered Users Online..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saqib389
Forum Commoner
Posts: 44
Joined: Wed Nov 30, 2005 2:13 am

Problem With Showing Registered Users Online..

Post 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"; 

?>
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

remove all that error supression "@" and see if you get something to pop up :-D
saqib389
Forum Commoner
Posts: 44
Joined: Wed Nov 30, 2005 2:13 am

Post by saqib389 »

error is still same
please helppppppppppppppppppp
:( :(
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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']}')");
saqib389
Forum Commoner
Posts: 44
Joined: Wed Nov 30, 2005 2:13 am

Post by saqib389 »

same thing...... same error.......

please guyz do some thing for this
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Post Reply