Question

I want to change session cookie path in ZF2. By default it is / I want to change it on /my_path/ I tried to do it with SessionManager

$config = new \Zend\Session\Config\StandardConfig();
$config->setOptions(array(
    'cookie_path' => '/my_path/',
));
$sessionManager = new \Zend\Session\SessionManager($config);
\Zend\Session\Container::setDefaultManager($sessionManager);
$sessionManager->start();

But it does not work


Resolve: change first line on $config = new \Zend\Session\Config\SessionConfig();

Was it helpful?

Solution

It's not enough to just create the session manager, you also need to tell the session containers about it, the Container class has a static method to do that. Add the following line to your code

    \Zend\Session\Container::setDefaultManager($sessionManager);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top