Hi all. I'm creating a user-profile page and I need to write if the user X is online or not. How can I do it ?
M.
On Tue, 27 Oct 2009 17:55:07 +0100 Michel Morelli michel@ziobuddalabs.it wrote:
Hi all. I'm creating a user-profile page and I need to write if the user X is online or not. How can I do it ?
I'd go for counting the sessions (whth/without uid). If you want to do it the drupal way you could give a look on how it is done in the Who's online block.
Ivan Sergio Borgonovo ha scritto:
I'd go for counting the sessions (whth/without uid). If you want to do it the drupal way you could give a look on how it is done in the Who's online block.
Ok. Thanks for the help.
M.
Michel Morelli ha scritto:
Hi all. I'm creating a user-profile page and I need to write if the user X is online or not. How can I do it ?
M.
Here my code. "theme286" is my theme.
//Here for an another element of the $account's fields in the user's account page.
theme286_preprocess_user_profile(&$vars) { $vars['account']->online = _user_online($vars['account']); }
//This is the real function. I have c&p code from "who's online" block. Thanks Ivan for the tips. function _user_online($account) { $interval = time() - variable_get('user_block_seconds_online', 900); // Perform database queries to gather online user lists. We use s.timestamp // rather than u.access because it is much faster. $online = db_result(db_query('SELECT u.uid FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid = %d LIMIT 1', $interval,$account->uid)); if ($online === false) return false; else return true; }
M.