-
Notifications
You must be signed in to change notification settings - Fork 64
php 7.2 with zend-session 2.8.3 : ini_set(): A session is active and 'session.use_cookies' is not a valid sessions-related ini setting error #104
Comments
I have also this error on my software, but in my case was session.cookie_lifetime |
Same error for me. |
What I'm seeing are two issues:
The root cause of this, of course, is that the session has already started by the time the |
The way call is by the |
I see the problem: Thus, in your code, you're calling The solution to this is to create your authentication storage instance via a factory, and have it pass a session manager instance pulled from the container to the storage constructor. You should also have a factory for creating the session manager instance that passes that configuration to it. |
I have the same issue, @weierophinney can you please be more specific? |
Identical issue like @samsonasik after upgrading from php 7 to php 7.2 |
@weirophinney I’m not sure if that can be a real fix, in php <= 7.1, we can create as many container as we want, eg: use Zend\Session\Container;
$a = new Container("foo");
$b = new Container("bar"); |
Here's what I meant: use Zend\Authentication\AuthenticationService;
use Zend\Session\Config\SessionConfig;
use Zend\Session\SessionManager;
use Zend\Session\Storage;
class SessionManagerFactory
{
public function __invoke(ContainerInterface $container)
{
$config = $container->has('config') ? $container->get('config') : [];
$config = $config['session'] ?? [];
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config);
// You could also configure the storage adapter, save handler, and
// validators here and pass them to the session manager constructor,
// if desired.
return new SessionManager($sessionConfig);
}
}
class AuthStorage extends Storage\Session
{
public function __construct(SessionManager $manager)
{
parent::__construct('auth', null, $manager);
}
}
class AuthStorageFactory
{
public function __invoke(ContainerInterface $container)
{
return new AuthStorage($container->get(SessionManager::class));
}
}
class AuthenticationServiceFactory
{
public function __invoke(ContainerInterface $container)
{
return new AuthenticationService($container->get(AuthStorage::class));
}
}
// Config:
return [
'dependencies' => [
'factories' => [
AuthenticationService::class => AuthenticationServiceFactory::class,
AuthStorage::class => AuthStorageFactory::class,
SessionManager::class => SessionManagerFactory::class,
],
],
];
// Retrieve the AuthenticationService from the container:
$authService = $container->get(AuthenticationService::class); @samsonasik — In terms of your last example, the solution to that is to pull the class FooController extends AbstractActionController
{
private $session;
public function __construct(SessionManager $session)
{
$this->session = $session;
}
public function indexAction()
{
$container = new Container('foo', $this->session);
}
} Note that the second argument to a Honestly, there's no way for us to fix this without requiring you pass the session manager instance to containers, which would be a BC break currently. |
is it possible to add handing at |
@samsonasik The problem is that the container calls That could potentially be moved to the first set/unset/exists operation, but the logic becomes quite brittle. Another approach is to use Again, my point here is that the order of operations is important. The approach you use above will not work under PHP 7.2, no matter what we do, if the manager has already started the session, and, by that point, it has. You need to configure the session first. |
@weierophinney I'm thinking if we can check with session_start();
if (session_status() === PHP_SESSION_ACTIVE) {
session_write_close(); // executed
}
ini_set('session.use_cookies', true);
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start(); // executed
}
$_SESSION['foo'] = 'foo';
var_dump(session_status() === PHP_SESSION_ACTIVE); // true So, the handling may be at |
@weierophinney I've created PR #107 for it |
Same error for me with php 7.2 |
Provide a narrative description of what you are trying to accomplish.
Code to reproduce the issue
Expected results
Working
Actual results
Got errors:
Env:
php version: 7.2
zend-session: 2.8.3
The text was updated successfully, but these errors were encountered: