因此,我将会话的生命周期设置为两周,这样用户就不必多次登录或退出。然而今天我注意到一些事情,如果您注销,它会破坏您的会话,但会在您的浏览器上保留“记住我”cookie。这会导致问题,因为如果您在同一台计算机上切换帐户 8-10 次,您会收到 400 bad request 错误,因为您发送的信息过多。现在,在 cookie 的正常生命周期中使用 8-10 次有点牵强,但当你的生命周期是两周时,我遇到了问题。
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? So far I have tried
Auth::logout();
Session::flush();
看来 cookie 不会自动取消设置。但是您可以在控制器中执行此操作在返回重定向响应之前注销后。
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);
}
记住要返回带有重定向的 cookie,否则它将无法工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)