You are here

function session_limit_session_limit in Session Limit 6.2

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

Implements hook_session_limit().

File

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

Code

function session_limit_session_limit($sid, $op) {
  switch ($op) {
    case 'collision':
      watchdog('session_limit', 'Exceeded maximum allowed active sessions.', array(), WATCHDOG_INFO);
      break;
    case 'disconnect':
      $message = variable_get('session_limit_logged_out_message', SESSION_LIMIT_LOGGED_OUT_MESSAGE);
      $message_severity = variable_get('session_limit_logged_out_message_severity', SESSION_LIMIT_LOGGED_OUT_MESSAGE_SEVERITY);
      if ($message_severity != '_none' && !empty($message)) {
        $logout_message = t($message, array(
          '@number' => session_limit_user_max_sessions(),
        ));
        $logout_message = 'messages|' . serialize(array(
          $message_severity => 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;
  }
}