You are here

function session_limit_init in Session Limit 5

Same name and namespace in other branches
  1. 6.2 session_limit.module \session_limit_init()
  2. 6 session_limit.module \session_limit_init()
  3. 7.2 session_limit.module \session_limit_init()

Implementation of hook_init().

Determine whether session has been verified.

File

./session_limit.module, line 55
Established Sessions do NOT need to verify every page load. new Session must deal w/ determining which connection is cut.

Code

function session_limit_init() {
  global $user;
  if (variable_get('session_limit_max', 1) && $user->uid > 1 && !isset($_SESSION['session_limit'])) {

    // Exclude from the redirect.
    if (arg(0) == 'session' && arg(1) == 'limit' || arg(0) == 'logout') {
      return;
    }
    if (module_exists('masquerade') && variable_get('session_limit_masquerade_ignore', false)) {
      $result = db_query('SELECT COUNT(s.uid) FROM {sessions} AS s
        LEFT JOIN {masquerade} AS m ON s.uid = m.uid_as AND s.sid = m.sid
        WHERE s.uid = %d AND m.sid IS NULL', $user->uid);
    }
    else {
      $result = db_query('SELECT COUNT(*) FROM {sessions} WHERE uid = %d', $user->uid);
    }
    if (db_result($result) > variable_get('session_limit_max', 1)) {

      // redirect to session handler.
      drupal_goto('session/limit');
    }
    else {

      // mark session as verified to bypass this in future.
      $_SESSION['session_limit'] = TRUE;
    }
  }
}