php – Laravel 4记住我到期时间

我对Laravel很新,有一个关于记住我的功能的问题.

我已经成功启用了“记住我”功能,通过附加第二个参数到Auth ::尝试方法,如此.

if (Auth::attempt(array('email' => $email,'password' => $password),true))
{
    // The user is being remembered...
}

如文档中所述,这可以无限期地记住我,或者直到用户手动注销.

我本来希望在“记住我”功能上设置一个到期日.

看着控制台,我可以看到,启用“记住我”会生成一个remember_ {HASH} cookie.

覆盖此cookie中指定的到期日的最佳方法是将来说一个星期?该cookie当前设置过去的日期,这使得它永远是最后的.

请记住,我必须设置’生命’=> 0在sessions.PHP中,以便我可以触发记住我的功能,基于用户偏好,所以将其改为一周将不会在我的情况下工作.

谢谢!

我不知道它是否是一个很好的方法,但是如果你绝望设置过期时间记住我,你可以尝试这个,但它对我来说是有效的.

让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
  }
});

注意:Cookie :: make(‘name’,’value’,’过期时间’);

相关文章

laravel的dd函数不生效怎么办
看不懂laravel文档咋办
安装laravel框架出现command怎么办
Laravel开发API怎么使用事务
laravel怎么构建复杂查询条件
laravel如何实现防止被下载