1.20.x admin_bar.module admin_bar_session_count($timestamp = 0, $anonymous = TRUE)

Counts how many users are active on the site.

Counts how many users have sessions which have been active since the specified time. Can count either anonymous sessions or authenticated sessions.

@todo There are mostly no anonymous sessions anymore. Split this into a separate module providing proper user statistics.

Parameters

$timestamp: A Unix timestamp. Users who have been active since this time will be counted. The default is 0, which counts all existing sessions.

$anonymous: TRUE counts only anonymous users. FALSE counts only authenticated users.

Return value

The number of users with sessions.:

File

modules/admin_bar/admin_bar.module, line 427
Render an administrative bar as a dropdown menu at the top of the window.

Code

function admin_bar_session_count($timestamp = 0, $anonymous = TRUE) {
  $query = db_select('sessions');
  $query->addExpression('COUNT(sid)', 'count');
  $query->condition('timestamp', $timestamp, '>=');
  $query->condition('uid', 0, $anonymous ? '=' : '>');
  return $query->execute()->fetchField();
}