Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !');
        }
like image 390
BaHar AyØub Avatar asked May 27 '13 14:05

BaHar AyØub


People also ask

How check session is present or not?

In ancient history you simply needed to check session_id() . If it's an empty string, then session is not started. Otherwise it is.

Where Symfony stores session?

However, if you have the following configuration, Symfony will store the session data in files in the cache directory %kernel. cache_dir%/sessions . This means that when you clear the cache, any current sessions will also be deleted: YAML.

What is session in Symfony?

Symfony provides a session object and several utilities that you can use to store information about the user between requests.


1 Answers

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

is what you're looking for.

like image 64
Nicolai Fröhlich Avatar answered Oct 04 '22 02:10

Nicolai Fröhlich