Zend Framework 1.10:不存储 Cookie
我正在尝试使用 Cookies 和 Zend Framework 1.10。这是我的代码:
$zendCookie = new Zend_Http_Cookie('foo', 'bar', 'localhost', time() + 60 * 60 * 24 * 30);
$client = new Zend_Http_Client();
$client->setCookie($zendCookie);
但是 cookie 没有被存储。我用Firecookie Firefox 的扩展检查了它。 怎么了?
I'm trying to with Cookies and Zend Framework 1.10. This is my code:
$zendCookie = new Zend_Http_Cookie('foo', 'bar', 'localhost', time() + 60 * 60 * 24 * 30);
$client = new Zend_Http_Client();
$client->setCookie($zendCookie);
But the cookies aren't stored. I checked it with Firecookie Firefox's extension.
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我什至使用 php 的 setcookie() 也遇到了同样的问题,但将域字段设置为空是可行的。虽然如果域字段留空,Zend_Http_Cookie() 会抛出异常。
Cookie 不适用于我的本地主机的虚拟主机
将域字段设置为空 - Cookie 已存储!
文档: setcookie()
I had this same problem even using php's setcookie(), but setting domain field to empty works. Although Zend_Http_Cookie() will throw an exception if domain field is left empty.
Cookie will not work with my localhost's virtualhost
Setting domain field to empty - Cookie stored!
Docs: setcookie()
本地主机用 cookie 做了一些奇怪的事情。
我将使用伪服务器名称设置一个虚拟主机,并将其作为主机文件中的一个条目并将其指向
127.0.0.1
IE:
然后在您的 /etc/hosts (或 C:\Windows\System32 \drivers\etc\hosts)您可以添加:
然后您可以通过调用 test.dev 在本地访问应用程序,并且您可以使用它来代替 cookie 的“localhost”,并且它不应该像 localhost 那样弄乱 cookie。您可以在 此处找到有关我正在谈论的 localhost cookies 的更多信息。
Localhost does some weird stuff with cookies.
I would setup a vhost with a psuedo server name and make this an entry in your hosts file and point it to
127.0.0.1
IE:
Then in your /etc/hosts (or C:\Windows\System32\drivers\etc\hosts) You would add:
Then you can access the application locally by calling test.dev and you would use that in place of "localhost" for the cookies and it should not mess with the cookies like localhost does. You can find a bit more information on what I am talking about with the localhost cookies here.
具有显式域的本地主机上的 Cookie
我认为问题是因为句号域名前缺少/句点,即“.domain.com”,只有某些浏览器会排除没有前导点的域名。
Cookies on localhost with explicit domain
I think the problem is because the full-stop/period is missing before the domain name i.e. ".domain.com" only some browsers will except the domain without the leading dot.