Kev*_*ung 12 php cookies remember-me laravel laravel-4
我对Laravel相当新,并且对于记住我的功能有一个疑问.
我通过在Auth :: attempt方法中附加第二个参数来成功启用"记住我"功能.
if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
// The user is being remembered...
}
Run Code Online (Sandbox Code Playgroud)
如文档中所述,这样可以无限期地记住我或直到用户手动注销.
我基本上想要设置"记住我"功能的过期日期.
看一下控制台,我可以看到启用"记住我"会生成一个remember_ {HASH} cookie.
覆盖此cookie中指定的过期日期的最佳方法是什么?Cookie目前设置过去的日期,这使它永远持续下去.
请记住,我必须在sessions.php中设置'lifetime'=> 0,以便我可以根据用户偏好触发记住我的功能,因此将此更改为一周在我的情况下不起作用.
谢谢!
Try*_*elf 15
我不知道它是否是一个很好的方法,但是如果你不顾一切地设定过期时间来记住我你可以试试这个,它对我有用.
让laravel Auth::atempt($credential,true)做正常的事情,即将记住我的到期时间设置为5年
我们将在App::after()方法中更改此方法,因此在您的filters.php文件中查找App::after()方法并更改cookie的到期时间
App::after(function($request, $response)
{
if ( Auth::check()){
$ckname=Auth::getRecallerName(); //Get the name of the cookie, where remember me expiration time is stored
$ckval=Cookie::get($ckname); //Get the value of the cookie
return $response->withCookie(Cookie::make($ckname,$ckval,360)); //change the expiration time
}
});
Run Code Online (Sandbox Code Playgroud)
注意:Cookie::make('name','value','expiration time');
| 归档时间: |
|
| 查看次数: |
7821 次 |
| 最近记录: |