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

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

问题描述

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

如果我们可以通过我们创建的每个会话从控制器中获得什么?谢谢.

解决方案

您可以通过更改 config/session.phplifetime 值来更改应用程序范围内的会话生命周期>:

/*|--------------------------------------------------------------------------|会话生存期|--------------------------------------------------------------------------||您可以在此处指定您希望会话的分钟数|允许在它到期之前保持空闲.如果你想要他们|要在浏览器关闭时立即过期,请设置该选项.|*/'终生' =>4320,'expire_on_close' =>错误的,

<小时>

现在,如果你想控制每个用户的会话生存期,你需要在登录用户之前设置这个值.

<块引用>

  1. 尝试数据库中是否存在用户
  2. 如果是,并且他是需要更长会话寿命的用户,请运行 config(['session.lifetime' => $newLifetime]);
  3. 登录用户
  4. 为当前用户享受更长的会话生命周期

来源

您必须在 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.

  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

Source

You have to make the above changes in LoginController.

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

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