You are here

function admin_menu_session_count in Administration menu 7.3

Same name and namespace in other branches
  1. 8.3 admin_menu.module \admin_menu_session_count()

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.

1 call to admin_menu_session_count()
admin_menu_get_user_count in ./admin_menu.module
Return count of online anonymous/authenticated users.

File

./admin_menu.module, line 584
Render an administrative menu as a dropdown menu at the top of the window.

Code

function admin_menu_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();
}