简体   繁体   English

Laravel Auth::logout 不删除记住我的 cookie

[英]Laravel Auth::logout not removing remember me cookie

So I have the lifetime of my sessions set to two weeks so users do not have to log in or out multiple times.因此,我将会话的生命周期设置为两周,这样用户就不必多次登录或注销。 However today I noticed something, if you log out it destroys your session but keeps the remember me cookie on your browser.但是今天我注意到了一些事情,如果您注销它会破坏您的会话,但会在您的浏览器上保留记住我的 cookie。 This causes issues because if you switch accounts enough on the same computer 8-10 times you get a 400 bad request error because you are sending too much information.这会导致问题,因为如果您在同一台计算机上切换帐户 8-10 次,您会收到 400 bad request 错误,因为您发送的信息太多。 now 8-10 times in a normal lifetime of a cookie is kind of far fetched but when your lifetime is two weeks I have run into issues.现在 8-10 次在一个 cookie 的正常生命周期中有点牵强,但是当你的生命周期是两周时,我遇到了问题。

This is a screenshot of what is happening when logging in and out a few times back to back.这是登录和退出几次背靠背时发生的情况的屏幕截图。在此处输入图像描述 How can I delete the lifetime cookie when a user logs out?用户注销时如何删除生命周期 cookie? So far I have tried到目前为止我已经尝试过

    Auth::logout();
    Session::flush();

It seems the cookie does not get unset automatically.似乎 cookie 不会自动取消设置。 However you can do this in your controller just before you return the redirect response after logout.但是,您可以在注销后返回重定向响应之前在控制器中执行此操作。

public function getLogout() {
    // your code here
    .....
    // Get remember_me cookie name
    $rememberMeCookie = Auth::getRecallerName();
    // Tell Laravel to forget this cookie
    $cookie = Cookie::forget($rememberMeCookie);

    return Redirect::to('/')->withCookie($cookie);
}

Just remember to return the cookie with the redirect, otherwise it won't work.只要记住用重定向返回cookie,否则它将不起作用。

就我而言,我需要传递所有参数,而不仅仅是名称。

\Cookie::queue(\Cookie::forget('cookieName',null,'.yourdomain.com'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM