You are here

function drupal_session_initialize in Zircon Profile 8

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

Initialize the session handler, starting a session if needed.

File

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

Code

function drupal_session_initialize() {
  global $user;
  session_set_save_handler('_drupal_session_open', '_drupal_session_close', '_drupal_session_read', '_drupal_session_write', '_drupal_session_destroy', '_drupal_session_garbage_collection');
  if (isset($_COOKIE[session_name()])) {

    // If a session cookie exists, initialize the session. Otherwise the
    // session is only started on demand in drupal_session_commit(), making
    // anonymous users not use a session cookie unless something is stored in
    // $_SESSION. This allows HTTP proxies to cache anonymous pageviews.
    drupal_session_start();
    if (!empty($user->uid) || !empty($_SESSION)) {
      drupal_page_is_cacheable(FALSE);
    }
  }
  else {

    // Set a session identifier for this request. This is necessary because
    // we lazyly start sessions at the end of this request, and some
    // processes (like drupal_get_token()) needs to know the future
    // session ID in advance.
    $user = drupal_anonymous_user();
    session_id(md5(uniqid('', TRUE)));
  }
  date_default_timezone_set(drupal_get_user_timezone());
}