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.