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 !');
}
In ancient history you simply needed to check session_id() . If it's an empty string, then session is not started. Otherwise it is.
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.
Symfony provides a session object and several utilities that you can use to store information about the user between requests.
$this->container->get('session')->isStarted()
is what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With