更新时间:2023-11-28 08:05:40
您可以通过更改 config/session.php
上的 lifetime
值来更改应用程序范围内的会话生命周期>:
/*|--------------------------------------------------------------------------|会话生存期|--------------------------------------------------------------------------||您可以在此处指定您希望会话的分钟数|允许在它到期之前保持空闲.如果你想要他们|要在浏览器关闭时立即过期,请设置该选项.|*/'终生' =>4320,'expire_on_close' =>错误的,
现在,如果你想控制每个用户的会话生存期,你需要在登录用户之前设置这个值.
config(['session.lifetime' => $newLifetime]);
— 来源
您必须在 LoginController
中进行上述更改.
Can we set expire time for each session in Laravel?
If we can how it possible from the controller by each session that we create? Thanks.
You can change the session lifetime, application wide by changing the lifetime
value on 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
You have to make the above changes in LoginController
.