【问题标题】:Remember Me token timeout not working in laravel 5.4记住我令牌超时在 laravel 5.4 中不起作用
【发布时间】:2019-06-21 09:33:06
【问题描述】:

在 Laravel 5.4 中,我自定义了身份验证模块的登录方法,并使用以下方法完成了用户登录:

if($request->remember== 1)
    Auth::loginUsingId($user_id,TRUE);
else
    Auth::loginUsingId($user_id);

在这里,当记住我复选框被选中时,我将第二个参数设置为 TRUE。

并在 sendLoginResponse 方法中自定义 cookie 时间:

$customRememberMeTimeInMinutes = 5;  
$rememberTokenCookieKey = Auth::getRecallerName(); 
Cookie::queue($rememberTokenCookieKey, Cookie::get($rememberTokenCookieKey), $customRememberMeTimeInMinutes);

完成上述步骤后,我记住我的令牌没有按预期工作(5 分钟后我刷新浏览器并且用户仍然登录)。

默认的Session配置是这样的

'lifetime' => 120,

'expire_on_close' => false,

请指出我做错了什么?

【问题讨论】:

    标签: php laravel remember-me


    【解决方案1】:

    记住我只是避免填写登录页面。它不保留会话。默认生命周期是 120(分钟),如果用户在这段时间内没有提交额外的请求,那么会话将丢失,并且会在某个时候被垃圾收集。如果要更改会话超时时间,则必须转到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' => 120,  // number of minutes you want to increase / decrease
    
    'expire_on_close' => false,
    

    【讨论】:

    • 会话中没有问题。我已经在 5 分钟内自定义记住我的令牌超时,刷新 5 分钟后仍然用户登录。Cookie 无法正常工作。
    • 要求是使用记住我登录的持久连接,自定义生命周期而不是laravel系统固定的5年。
    猜你喜欢
    • 2020-12-24
    • 2019-10-19
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 2015-10-10
    • 2018-07-20
    • 2017-10-23
    相关资源
    最近更新 更多