No way to tell if session has just started.

Created on 29 March 2019, almost 6 years ago
Updated 12 March 2024, 11 months ago

There is no way tell if session has just been started. isStarted() will only be true if session has been regenerated from session id in session cookie, but will be false if session has just started and a set-cookie header will be sent in the current request. I believe this is a bug, as the code from NativeSessionStorage would correctly return TRUE for isStarted if it wasn't overridden in core SessionManager.

      // NativeSessionStorage::loadSession() sets started to TRUE, reset it to
      // FALSE here.
      $this->started = FALSE;
      $this->startedLazy = TRUE;

Method isStarted is not overridden and will return FALSE. There is no method to check startedLazy property either.

Here is an example code to reproduce the issue:

    if (!\Drupal::request()->getSession()->isStarted()) {
      // I am trying to start the session:
      $_SESSION['start1'] = TRUE;
      \Drupal::request()->getSession()->set('start2', TRUE);
      \Drupal::request()->getSession()->start();
      // Checking the results - still FALSE!
      $started = \Drupal::request()->getSession()->isStarted();
    }
πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 10 hours ago

Created by

πŸ‡§πŸ‡¬Bulgaria miroslavbanov

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024