You are here

function drupal_session_commit in Memcache Storage 7

Commits the current session, if necessary.

If an anonymous user already have an empty session, destroy it.

File

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

Code

function drupal_session_commit() {
  global $user, $is_https;
  if (!drupal_save_session()) {

    // We don't have anything to do if we are not allowed to save the session.
    return;
  }
  if (empty($user->uid) && empty($_SESSION)) {

    // There is no session data to store, destroy the session if it was
    // previously started.
    if (drupal_session_started()) {
      session_destroy();
    }
  }
  else {

    // There is session data to store. Start the session if it is not already
    // started.
    if (!drupal_session_started()) {
      drupal_session_start();
      if ($is_https && variable_get('https', FALSE)) {
        $insecure_session_name = substr(session_name(), 1);
        $params = session_get_cookie_params();
        $expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;
        setcookie($insecure_session_name, $_COOKIE[$insecure_session_name], $expire, $params['path'], $params['domain'], FALSE, $params['httponly']);
      }
    }

    // Write the session data.
    session_write_close();
  }
}