thomas
thomas

Reputation: 11

Zend Framework 1.10: Cookies aren't stored

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?

Upvotes: 0

Views: 715

Answers (3)

gawpertron
gawpertron

Reputation: 1927

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.

Upvotes: 0

Edward Hew
Edward Hew

Reputation: 134

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

setcookie ( 'FOO', 'cookie content', 0, '/', 'myProjectSiteVHost', true, true);

Setting domain field to empty - Cookie stored!

setcookie ( 'FOO', 'cookie content', 0, '/', '', true, true);

Docs: setcookie()

Upvotes: 1

Jim
Jim

Reputation: 18853

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:

<VirtualHost *:80>
    ServerName test.dev
    #(other required / normal items here)
</VirtualHost>

Then in your /etc/hosts (or C:\Windows\System32\drivers\etc\hosts) You would add:

127.0.0.1        test.dev

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.

Upvotes: 0

Related Questions