5

There is a lot of questions how to check the current user is logged in, but I need to check another users (by uid for example). Is there any easy way to do it?

4

There aren't any functions in Drupal that I am aware of. You'll need to query the database.

$time_active = db_query("SELECT timestamp FROM {sessions} WHERE uid = :uid ORDER BY timestamp DESC LIMIT 1", array(":uid" => $uid))->fetchField();

That will fetch the last time that the user was active if they have a current session open.

0

Hope this will help you,

You can use sessions table. You can fetch a list of all logged in users by querying the sessions table


// Check if user $uid is online in the last 10 minutes
$online = db_query("SELECT uid FROM {sessions} 
          WHERE uid = :uid 
          AND timestamp >= :time", array(':uid' => $uid, ':time' => (REQUEST_TIME - 600))->fetchField();

Reference : Check if user is online

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.