Laravel 4 会话在生命周期限制后不会过期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24424607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 session doesn't expire after lifetime limit
提问by Tom
I've set 'lifetime' => 10
in my session config file, but it doesn't expire at all.
我已经'lifetime' => 10
在我的会话配置文件中进行了设置,但它根本没有过期。
In laravel 3 with that setting, after logging in, when limit of 10 minutes is exceeded, the session expires properly and user is redirected to login again.
在具有该设置的 laravel 3 中,登录后,当超过 10 分钟的限制时,会话会正确过期,并且用户将被重定向到再次登录。
In laravel 4 it doesn't happen. After 10 minutes I can refresh, do anything and still session is valid.
在 Laravel 4 中它不会发生。10 分钟后,我可以刷新、做任何事情并且会话仍然有效。
I'm testing both on the same machine with analogical settings... What am I missing?
我正在使用类比设置在同一台机器上测试两者......我错过了什么?
回答by Tom
I've got it. The problem was with the config pair lifetime
and expire_on_close
.
我懂了。问题出在配置对lifetime
和expire_on_close
.
If expire_on_close
is set to true, laravel 4 will ignore lifetime
. I had:
如果expire_on_close
设置为 true,laravel 4 将忽略lifetime
. 我有:
'lifetime' => 1,
'expire_on_close' => true,
and in this case, session was valid after 1 min - it would only expire after closing browser. I changed it to:
在这种情况下,会话在 1 分钟后有效 - 它只会在关闭浏览器后过期。我把它改成:
'lifetime' => 1,
'expire_on_close' => false,
and now session is expiring after 1 min. no matter if browser is closed or not - close enough to what I've wanted.
现在会话将在 1 分钟后到期。无论浏览器是否关闭 - 足够接近我想要的。
The reason why I was confused and haven't figured it out earlier was that the comments there are unclear in that matter and that in Laravel 3 it worked differently...
我感到困惑并且没有早点弄明白的原因是那里的评论在这件事上不清楚,而且在 Laravel 3 中它的工作方式不同......