function drupal_session_commit

Commits the current session, if necessary.

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

3 calls to drupal_session_commit()
drupal_exit in drupal/core/includes/common.inc
Performs end-of-request tasks.
FinishResponseSubscriber::onRespond in drupal/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
Sets extra headers on successful responses.
_session_test_id in drupal/core/modules/system/tests/modules/session_test/session_test.module
Menu callback: print the current session ID.

File

drupal/core/includes/session.inc, line 298
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();
  }
}