php - Unable to set the remember me cookie expiry date in laravel 4.1.28 -
background:
i using laravel 4.0.x , , resetting remember_me cookie expiry date 1 month (since default 5 years ) using code :
app::after(function($request, $response) { // if user tryin log_in , wants stay logged in, reset remember_me cookie expiration date 5 years 1month $remember = input::get('remember',false); if ($remember) { if ( auth::check()){ // check if user logged in $ckname = auth::getrecallername(); //get name of cookie, remember me expiration time stored $ckval = cookie::get($ckname); //get value of cookie return $response->withcookie(cookie::make($ckname,$ckval,43200)); //change expiration time 1 month = 43200 min } }
that code app\filters.php of course, , working charm.
the problem :
i updated laravel 4.0.x v4.1.28, , remember_me cookies set 5 years, tried last hours digging in code trying debug no luck :( .
notice changing $ckname value "test" in last line of above code works fine, creates "test" cookie expiry of 1 month intended
return $response->withcookie(cookie::make("test",$ckval,43200));
i don't understand why remember_me cookie persist 5 years expiry date !
any appreciated :)
abdou.
update:
the question not why want change cookie expiry date, it's why cookie won't updated?! . thanks.
this intentional behavior laravel.
the remember_me settings "permanently" remember user, until such time 'logout' of application.
if dig auth classes - says "permanent cookie".
public function login(userinterface $user, $remember = false) { $this->updatesession($user->getauthidentifier()); // if user should permanently "remembered" application // queue permanent cookie contains encrypted copy of user // identifier. decrypt later retrieve users. if ($remember) { $this->createremembertokenifdoesntexist($user); $this->queuerecallercookie($user); }
there no way set cookie other 'permanent' (aka 5 years).
also - the laravel docs state remember me forever:
if provide "remember me" functionality in application, may pass true second argument attempt method, keep user authenticated indefinitely (or until manually logout)
edit: you've updated question - looked more. works me:
public function login() { if (auth::attempt(array('email' => input::get('email'), 'password' => ), true)) { $ckname = auth::getrecallername(); cookie::queue($ckname, cookie::get($ckname), 43200); return view::make('welcome'); } }
it sets 'remember_me' cookie 1 month.
Comments
Post a Comment