Laravel会话的每个会话过期时间 [英] Laravel session expire time for each session

查看:381
本文介绍了Laravel会话的每个会话过期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在 Laravel 中为每个会话设置过期时间吗?

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.

推荐答案

您可以通过更改config/session.php上的lifetime值来更改应用程序范围的会话生存期:

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.

  1. 尝试在数据库中是否存在用户
  2. 如果是,并且他是需要更长会话寿命的用户,请运行config(['session.lifetime' => $newLifetime]);
  3. 登录用户
  4. 为当前用户享受更长的会话寿命
  1. Try if user exists in database
  2. If yes, and he is user who needs longer session lifetime, run config(['session.lifetime' => $newLifetime]);
  3. Log user in
  4. Enjoy longer session lifetime for current user

-来源

您必须在LoginController中进行上述更改.

You have to make the above changes in LoginController.

这篇关于Laravel会话的每个会话过期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆