1 session.inc backdrop_session_commit()

Commits the current session, if necessary.

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

File

core/includes/session.inc, line 309
User session handling functions.

Code

function backdrop_session_commit() {
  global $user, $is_https;

  if (!backdrop_save_session()) {
    // We don't have anything to do if we are not allowed to save the session.
    return TRUE;
  }

  if (empty($user->uid) && empty($_SESSION)) {
    // There is no session data to store, destroy the session if it was
    // previously started.
    if (backdrop_session_started()) {
      session_destroy();
    }
  }
  else {
    // There is session data to store. Start the session if it is not already
    // started.
    if (!backdrop_session_started()) {
      backdrop_session_start();
      if ($is_https && settings_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();
  }
  return TRUE;
}