You are here

function session_limit_session_limit in Session Limit 6

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

Implementation of hook_trigger_name().

File

./session_limit.module, line 424
Limits multiple sessions per user.

Code

function session_limit_session_limit($sid, $op) {
  $aids = _trigger_get_hook_aids('session_limit', $op);
  $context = array(
    'hook' => 'session_limit',
    'op' => $op,
    'sid' => $sid,
  );
  actions_do(array_keys($aids), $user, $context);
  switch ($op) {
    case 'collision':
      watchdog('session_limit', 'Exceeded maximum allowed active sessions.', array(), WATCHDOG_INFO);

      // redirect to session handler.
      drupal_goto('session/limit');
      break;
    case 'disconnect':
      $logout_message = t('You have been automatically logged out. Someone else has logged in with your username and password and the maximum number of @number simultaneous sessions was exceeded. This may indicate that your account has been compromised or that account sharing is not allowed on this site. Please contact the site administrator if you suspect your account has been compromised.', array(
        '@number' => session_limit_user_max_sessions(),
      ));
      $logout_message = 'messages|' . serialize(array(
        'error' => array(
          $logout_message,
        ),
      ));
      db_query("UPDATE {sessions} SET uid = 0, session = '%s' WHERE sid = '%s'", $logout_message, $sid);
      watchdog('session_limit', 'Disconnected for excess active sessions.', array(), WATCHDOG_NOTICE);
      break;
  }
}