[support] how to know if a user is online
Michel Morelli
michel at ziobuddalabs.it
Wed Oct 28 11:16:24 UTC 2009
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.
--
Michel 'ZioBudda' Morelli michel at ziobuddalabs.net
Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax)
Telefono: 0200619074
Telefono Cell: +39-3939890025 -- Fax: +39-0291390660
http://www.ziobudda.net ICQ: 58351764
http://www.ziobuddalabs.it Skype: zio_budda
http://www.ziodrupal.net MSN: michel at ziobuddalabs.it
JABBER: michel at ziobuddalabs.it
More information about the support
mailing list