【问题标题】:Automatically logout user when session expires in Laravel 5在 Laravel 5 中会话到期时自动注销用户
【发布时间】:2017-06-25 04:48:35
【问题描述】:

有没有办法在 Laravel 中会话到期后立即注销用户?我知道也许最简单的替代方法是在会话过期后发送请求时让注销发生,事实上这就是我在我的网站中处理它的方式,但由于前端的一些问题,我不再可以做到这一点。有什么想法吗?

【问题讨论】:

  • 我能想到的唯一方法是从 FE 安排一个简单的检查调用并检查状态。
  • 如果有人关闭浏览器怎么办,你从哪里得到那个请求...
  • 请添加一些您之前尝试过的代码。
  • 难道你只是将生命周期设置为 x 秒并让 laravel 处理这个,你需要在前端处理 403 状态代码(假设你已经这样做了)?

标签: php laravel session


【解决方案1】:

Laravel 会处理这个问题并提供一个配置文件 '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' => 43200,

    'expire_on_close' => false,

【讨论】:

    猜你喜欢
    • 2017-09-30
    • 1970-01-01
    • 2012-04-19
    • 2019-06-17
    • 2021-12-09
    • 2015-04-12
    • 2018-03-01
    • 2017-06-22
    • 2018-12-25
    相关资源
    最近更新 更多