BaHar AyØub
BaHar AyØub

Reputation: 337

Symfony2: check whether session exists or not

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 !');
        }

Upvotes: 9

Views: 8244

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52493

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

is what you're looking for.

Upvotes: 16

Related Questions