每个会话的 Laravel 会话过期时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48859424/
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 session expire time for each session
提问by Nasser Ali Karimi
Can we set expire time for each session in Laravel?
我们可以在Laravel 中为每个会话设置过期时间吗?
If we can how it possible from the controller by each session that we create? Thanks.
如果我们可以通过我们创建的每个会话从控制器中获得什么?谢谢。
回答by Jomoos
You can change the session lifetime, application wide by changing the lifetime
value on config/session.php
:
您可以通过更改上的lifetime
值来更改应用程序范围内的会话生存期config/session.php
:
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 4320,
'expire_on_close' => false,
Now, if you want to control the session lifetime per user, you need to set this value before logging in the user.
现在,如果要控制每个用户的会话生存期,则需要在用户登录之前设置此值。
- Try if user exists in database
- If yes, and he is user who needs longer session lifetime, run
config(['session.lifetime' => $newLifetime]);
- Log user in
- Enjoy longer session lifetime for current user
— Source
- 尝试用户是否存在于数据库中
- 如果是,并且他是需要更长会话寿命的用户,请运行
config(['session.lifetime' => $newLifetime]);
- 登录用户
- 为当前用户享受更长的会话寿命
—来源
You have to make the above changes in LoginController
.
您必须在LoginController
.