【发布时间】:2014-07-05 23:52:45
【问题描述】:
背景:
我正在使用 laravel 4.0.x,并使用此代码将 remember_me cookie 的到期日期重置为 1 个月(因为默认值为 5 年):
App::after(function($request, $response)
{
// If the user is tryin to log_in and he wants to stay logged in, reset the remember_me cookie expiration date from 5 years to 1month
$remember = Input::get('remember',false);
if ($remember) {
if ( Auth::check()){ // check if the user is logged in
$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,43200)); //change the expiration time to 1 month = 43200 min
}
}
该代码当然来自 app\filters.php,而且它的工作原理非常有魅力。
问题:
我最近将 laravel 从 4.0.x 更新到 v4.1.28,现在 remember_me cookie 设置为 5 年,我在最后几个小时尝试挖掘代码尝试调试但没有运气:( .
请注意,在上述代码的最后一行中将 $ckname 更改为另一个值,如 "test" 就可以了,它会创建一个 "test" 像我预期的那样过期 1 个月的 cookie
return $response->withCookie(Cookie::make("test",$ckval,43200));
我真的不明白为什么 remember_me cookie 会持续到 5 年到期日期!
任何帮助将不胜感激:)
阿卜杜。
更新:
问题不是我为什么要更改 cookie 到期日期,而是为什么 cookie 不会更新?! .谢谢。
【问题讨论】:
-
您是否遵循此处的升级指南:laravel.com/docs/upgrade?同样在 app/config/session.php 中,您是否将“lifetime”属性设置为非零值(如 120)?
-
是的,我遵循了整个升级指南,并且生命周期设置为 120,坦率地说我不相信这与配置有关,因为 cookie 设置正常,所以问题只是5年内:/
-
您是否在使用任何其他软件包,例如 Cartalysts Sentry?
-
不,只有 jeffrey way generator,我相信这与这个问题无关。
-
您为什么不希望它是永久性的?为什么要让它过期?
标签: php cookies laravel laravel-4 remember-me