【发布时间】:2014-10-27 05:40:09
【问题描述】:
不知何故,我的 Laravel (4.2) 应用停止了创建 cookie(因此,它停止将会话与这些 cookie 链接起来)。我正在运行我在另一篇文章中看到的这个测试:
// 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'));
});
因此,如果我在浏览器中打开 /cookieset,则会创建 cookie 本身(可以在 Reditect:: 之前 dd($cookie) to()。我得到这个结果:
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)
}
但是,当重定向到 /cookieget 时,我得到了 NULL 结果。
浏览器(谷歌浏览器)没有任何“foo”cookie。
我已经在其他 Laravel 项目中尝试过相同的代码并且工作正常。我不记得改变任何可能破坏框架的东西。我还更新了框架(到 4.2.8),得到了相同的结果。
感谢您的帮助。
【问题讨论】:
标签: php session cookies laravel