我正在尝试设置与\Zend\Session\Container的会话的最大生存时间。为了测试它,我把它设置为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
但同样没有成功。
因此,在所有的搜索之后,我无法让它工作,所以现在我希望其他人能让它工作,并能帮助我。
发布于 2014-07-21 17:15:48
我终于发现问题出在哪里了。
问题是我用了
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(array(
'use_cookies' => true,
'cookie_httponly' => true,
'gc_maxlifetime' => $config['authTimeout'],
));
$manager = new SessionManager($sessionConfig);这个“工作”唯一的问题是设置了一个带有生命周期session的cookie。这在浏览器中是不同的。在铬,它是销毁,如果你关闭标签,所以无论多高的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']为正整数值
发布于 2013-10-23 03:00:55
$config = new StandardConfig();
$config->setOptions(array(
'cookie_lifetime' => '2419200',
'gc_maxlifetime' => '2419200'
));将2419200的值更改为您实际需要的秒数。
发布于 2013-10-26 20:06:06
在应用程序global.php中,或者您可以在模块配置中执行此操作:
'session_config' => array(
'name' => 'your session name',
'remember_me_seconds' => 60 * 60 * 24 * 30*3,
'use_cookies' => true,
'cookie_httponly' => true,
),检查Zend\Session\Service\SessionConfig。
https://stackoverflow.com/questions/19525329
复制相似问题