MyBB Community Forums

Full Version: SOLVED: some help please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was wondering if I could get some help with something. I have a variable that carries I users ID. What I want to know is how I would go about using that ID and determine if the user with that ID is online/offline. This would have to be PHP code that could be used on a page outside the forum directory. Any help would be appreciated.


 $query = $db->query("SELECT * FROM ".TABLE_PREFIX."sessions where uid='$uid'");
$cov = $db->fetch_array($query);
if(!$cov)
{
	$status ="offline";
} else {
	$status = "online";
}

a simple code, but this is the actually query to do so.

regards
Thanks, I'll give it a try.
Alright, it seems to work fine. But earlier today I was taking a look at the sessions table in my database and for some reason it has sessions for users who are not online not to mention tons of sessions for the user 0. Does anyone know why these sessions are still in the database even though the users not online?
Hello there,

The 0s are acutally the Guests.

now in case some results were not so precise, then add to the query

AND time=time() 

regards
Yeah, I knew that 0 represented guests but when I look at the guest count on my forum index it says 2, the session table shows 20+. I added that code to the query and now everyone is showing up offline, even when online.
aha i see!

Add this above the query
$timedisp = time() - $mybb->settings['wolcutoffmins']*60;

instead of what i have proposed in the previous post add to the query

AND time>'$timedisp' 

i guess this will help
regards
Thanks, it works perfect now. Smile