9

Is there a method to check whether a session exists or not?

I tried this method, but it always gives me a 'Bravo !' answer:

        $session = $this->getRequest()->hasPreviousSession();

        if($session)
        {
            return new Response('Bravo !');

        }
        else
        {
            return new Response('Oooops !');
        }
Thomas Landauer
  • 7,857
  • 10
  • 47
  • 99
BaHar AyØub
  • 337
  • 2
  • 6
  • 15

1 Answers1

16
$this->container->get('session')->isStarted()

is what you're looking for.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • 1
    Wrong. `isStarted` returns `false` unless you call `get` or `set` even if the request actually has a session. – Finesse Jul 15 '18 at 10:40