A function that shows online users either anonymous, authenticated, or both.
/**
* Returns number of users online
*
* @param $type
* can be 'anon', 'auth', or '' which returns both
*/
function deuxcode_users_online($type = '') {
$interval = time() - variable_get('user_block_seconds_online', 900);
switch ($type) {
case 'anon':
$users_count = sess_count($interval);
break;
case 'auth':
$users_count = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval));
break;
default:
$count_anon = sess_count($interval);
$count_auth = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval));
$users_count = $count_anon + $count_auth;
break;
}
return $users_count;
}
Comments
Post new comment