views:

48

answers:

3

Hi, 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?

Thank you.

A: 

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.

Brad F Jacobs
A: 

I don't know how to do that on Linux but i will search it on Google premiso. hsz, my request object doesn't have a setCookie method. Thank you guys.

Thomas
What system are you running? If debian based the virtualhost file should be located at /etc/apache2/sites-available/default
Brad F Jacobs
Dont post answers with messages like that. We have a comments feature for just that :)
Iznogood
A: 

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()

doingsitups