gpt4 book ai didi

php - Zend Framework 2 session 生命周期

转载 作者:可可西里 更新时间:2023-11-01 14:03:07 24 4
gpt4 key购买 nike

我正在尝试使用 \Zend\Session\Container 设置 session 的最长生命周期。为了测试它,我把它设置为 1 秒。

现在我查看了 docs

我也是这样

$config = new StandardConfig();
$config->setOptions(array(
'remember_me_seconds' => 1,
));
$manager = new SessionManager($config);
$session = new Container('user', $manager);

但是没有成功。然后我开始谷歌搜索并找到this answer

所以我做了配置

return array(
'session' => array(
'remember_me_seconds' => 2419200,
'use_cookies' => true,
'cookie_httponly' => true,
),
);

(配置有效并加载到管理器中)但还是没有成功

于是我继续寻找,找到了this answer

但还是没有成功。

所以在所有搜索之后我无法让它工作,所以现在我希望有人让它工作并且可以帮助我。

最佳答案

好吧,我终于找到了问题所在。

问题是我用过

$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(array(
'use_cookies' => true,
'cookie_httponly' => true,
'gc_maxlifetime' => $config['authTimeout'],
));
$manager = new SessionManager($sessionConfig);

这个“有效”的唯一问题是设置了一个具有生命周期 session 的 cookie。这在浏览器中带来了不同的东西。即在 chrome 中,如果您关闭选项卡,它就会被破坏,所以无论 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);

希望对以后的人有所帮助

$config['authTimeout'] 是一个正整数值

关于php - Zend Framework 2 session 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com