MKr*_*ers 5 php session zend-framework2
我正在尝试设置会话的最长生命时间\Zend\Session\Container.为了测试它,我把它放到1秒.
现在我查看了文档
所以我做了
$config = new StandardConfig();
$config->setOptions(array(
'remember_me_seconds' => 1,
));
$manager = new SessionManager($config);
$session = new Container('user', $manager);
Run Code Online (Sandbox Code Playgroud)
但没有成功.然后我开始谷歌搜索,找到了这个答案
所以我做了配置
return array(
'session' => array(
'remember_me_seconds' => 2419200,
'use_cookies' => true,
'cookie_httponly' => true,
),
);
Run Code Online (Sandbox Code Playgroud)
(配置工作并加载到管理器中)但再次没有成功
所以我继续搜索并找到了答案
但再没有成功.
因此,经过所有的搜索,我无法让它工作,所以现在我希望其他人得到它的工作,并可以帮助我.
好吧,我最终发现了问题所在.
问题是我用过
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(array(
'use_cookies' => true,
'cookie_httponly' => true,
'gc_maxlifetime' => $config['authTimeout'],
));
$manager = new SessionManager($sessionConfig);
Run Code Online (Sandbox Code Playgroud)
这个"工作"唯一的问题是有一个生命周期的cookie session.这在浏览器中有不同的东西.即铬合金,如果你关闭标签,它就会被破坏,所以无论多高gc_maxlifetime都不行.
因此,以下是一个简单的解决方案
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(array(
'use_cookies' => true,
'cookie_httponly' => true,
'gc_maxlifetime' => $config['authTimeout'],
'cookie_lifetime' => $config['authTimeout'],
));
$manager = new SessionManager($sessionConfig);
Run Code Online (Sandbox Code Playgroud)
希望它会有所帮助
$config['authTimeout'] 是一个正整数值