You are here

function _drupal_session_destroy in Memcache Storage 7

Session handler assigned by session_set_save_handler().

Cleans up a specific session.

Parameters

$sid: Session ID.

1 string reference to '_drupal_session_destroy'
drupal_session_initialize in includes/session.inc
Initializes the session handler, starting a session if needed.

File

includes/session.inc, line 414
User session handling functions.

Code

function _drupal_session_destroy($sid) {
  global $user, $is_https;

  // Nothing to do if we are not allowed to change the session.
  if (!drupal_save_session()) {
    return;
  }

  // Load session from memcached.
  $session = MemcacheStorageAPI::get($sid, 'sessions');

  // Remove current sid from sessions map.
  if (!empty($session->uid)) {

    // Load sessions map for authenticated user.
    $current_sessions = MemcacheStorageAPI::get($session->uid, 'sessions_map');
    if (!empty($current_sessions[$sid])) {
      unset($current_sessions[$sid]);
      if (empty($current_sessions)) {
        MemcacheStorageAPI::delete($session->uid, 'sessions_map');
      }
      else {
        MemcacheStorageAPI::set($session->uid, $current_sessions, 0, 'sessions_map');
      }
    }
  }

  // Delete session data.
  MemcacheStorageAPI::delete($sid, 'sessions');

  // Reset $_SESSION and $user to prevent a new session from being started
  // in drupal_session_commit().
  $_SESSION = array();
  $user = drupal_anonymous_user();

  // Unset the session cookies.
  _drupal_session_delete_cookie(session_name());
  if ($is_https) {
    _drupal_session_delete_cookie(substr(session_name(), 1), FALSE);
  }
  elseif (variable_get('https', FALSE)) {
    _drupal_session_delete_cookie('S' . session_name(), TRUE);
  }
}