function SessionManager::start

Same name in other branches
  1. 9 core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::start()
  2. 8.9.x core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::start()
  3. 11.x core/lib/Drupal/Core/Session/SessionManager.php \Drupal\Core\Session\SessionManager::start()

File

core/lib/Drupal/Core/Session/SessionManager.php, line 114

Class

SessionManager
Manages user sessions.

Namespace

Drupal\Core\Session

Code

public function start() : bool {
    if (($this->started || $this->startedLazy) && !$this->closed) {
        return $this->started;
    }
    $request = $this->requestStack
        ->getCurrentRequest();
    $this->setOptions($this->sessionConfiguration
        ->getOptions($request));
    if ($this->sessionConfiguration
        ->hasSession($request)) {
        // If a session cookie exists, initialize the session. Otherwise the
        // session is only started on demand in save(), making
        // anonymous users not use a session cookie unless something is stored in
        // $_SESSION. This allows HTTP proxies to cache anonymous page views.
        $result = $this->startNow();
    }
    if (empty($result)) {
        // Initialize the session global and attach the Symfony session bags.
        $_SESSION = [];
        $this->loadSession();
        // NativeSessionStorage::loadSession() sets started to TRUE, reset it to
        // FALSE here.
        $this->started = FALSE;
        $this->startedLazy = TRUE;
        $result = FALSE;
    }
    return $result;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.