MyBB Community Forums

Full Version: User online??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Where is the user online status stored in MySQL?

I want to check if a user is logged on or off in a script.

Ideally I'd like to check if a username is in an array of logged in users.

if (in_array ($user, $array_of_loggedin_users)) {

do this;

}

The following is actually not what I'm after: $mybb->user['uid'] or $mybb->user['username'] only returns the user id or username for the user currently visiting the page.
if ($mybb->user['uid'] != "0")
{
   echo "Hello ".$mybb->user['username']." How are you?";
}
That doesn't seem to do it. I want to check if an particular user is online from uid.
Where you want to show it?
What do you want to do it ?

For particular user, Change;
if ($mybb->user['uid'] != "0")
to;
if ($mybb->user['uid'] == "X")

Where X is a particular UserID.
Ah, got it. Thanks again!

I'm using it for AJAXCHAT. Ajaxchat doesn't always mark users as logged-out in (SELECT userName FROM ajax_chat_online)

Where is the user online status stored in MySQL?

I want to check if a user is logged on or off in a script.

Ideally I'd like to check if a username is in an array of logged in users.


if (in_array ($user, $array_of_loggedin_users)) {

do this;

}

The following is actually not what I'm after: $mybb->user['uid'] or $mybb->user['username'] only returns the user id or username for the user currently visiting the page.
This is how MyBB detects whether a user is online or not in the profile:

$timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
$query = $db->simple_select("sessions", "location,nopermission", "uid='$uid' AND time>'{$timesearch}'", array('order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 1));
$session = $db->fetch_array($query);
	
if(!empty($session))
{
	// User is online
}

(member.php, line 1833)

Basically it compares the current time with a user's last action timestamp from the sessions table. If the timestamp is greater than the current time then the user is online. Otherwise the user is offline and $session will be empty.
I see. So idle users will go offline after a period of time?
Yes. That period of time is $mybb->settings['wolcutoffmins']. It's a bit difficult to know whether a user is just taking a long time to read a thread or if he closed the window, so MyBB gives users a little timeoff (15 minutes by default). If I read a thread for longer than 15 minutes I will go offline. If I read the thread in five seconds and close the window then I will only go offline in 15 minutes.
Ok. Nice explanation.

Thank you!

If a user clicks "log out" does it force the time (15 min) to expire? I wouldn't see a point in waiting the time limit if a user clicks 'log out'.
If the user logs out then the session is destroyed and the user goes offline immediately.
Pages: 1 2