Out of nowhere, my Laravel (4.2) app stopped creating cookies (therefore, it stopped to link sessions with those cookies). I'm running this test that I saw in another post:
// routes.php
Route::get('cookieset', function(){
$cookie = Cookie::make('foo', 'bar', 60);
return Redirect::to('cookieget')->withCookie($cookie);
});
Route::get('cookieget', function(){
dd(Cookie::get('foo'));
});
So if I open /cookieset in the browser, the cookie itself gets created (It is posible to dd($cookie) before the Reditect::to() . I get this result:
object(Symfony\Component\HttpFoundation\Cookie)#165 (7) {
["name":protected]=> string(3) "foo"
["value":protected]=> string(3) "bar"
["domain":protected]=> NULL
["expire":protected]=> int(1409694104)
["path":protected]=> string(1) "/"
["secure":protected]=> bool(false)
["httpOnly":protected]=> bool(true)
}
However, when redirected to /cookieget , I got a NULL result.
The browser (Google Chrome) dosen't have any "foo" cookies.
I have tried this same code in other Laravel projects and works fine. I don't remember changing anything that could break the framework. I also updated the framework (to 4.2.8) and I get the same result.
I appreciate your help.
SOLVED: Apparently, my routes.php file was the issue. It might had some "strange" white character somewhere, so the cookies (therefore the session) never got created. I just created a new routes.php file and everything works fine now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.