You are here

function drupal_session_commit in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 modules/memcache/unstable/memcache-session.inc \drupal_session_commit()

Commit the current session, if necessary.

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

File

modules/memcache/unstable/memcache-session.inc, line 227

Code

function drupal_session_commit() {
  global $user;
  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();
    }

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