Results 1 to 6 of 6

Thread: Zend_Http_Cookie on localhost

  1. #1
    Snef is offline Junior Member
    Join Date
    Jul 2007
    Posts
    8

    Default Zend_Http_Cookie on localhost

    Hi,

    I want to create a cookie, but it doesn't seem to work on localhost.

    Does any body used it before and give me some guidelines other than the documentation?

    Snef

  2. #2
    millhost is offline Junior Member
    Join Date
    Dec 2007
    Posts
    3

    Default

    Yes, I am facing the same problem.
    I tried this code, but it seems not working.
    $client = new Zend_Http_Client("http://www.abc.com");
    $client->setCookie('var','value',time() + 2678400,'/');

    Could anyone can give us some hints.

  3. #3
    xentek is offline Senior Member
    Join Date
    Feb 2008
    Posts
    112

    Default

    Check out the setcookie documentation on php.net ... there are some caveats with setting cookies that you may be running into. Also, try setting all of the paramaters, even if you want the defaults (just set the defaults), as this can sometimes cause issues in some browsers, which result in the cookie not being set (without error).

  4. #4
    aaron78 is offline Junior Member
    Join Date
    Nov 2008
    Posts
    9

    Default

    This seems to be a bit of a gotcha with ZF in my opinion.

    If you checkout the PHP docs on the normal setcookie method here:
    PHP: setcookie - Manual and do a text search on 'localhost', you will find comments saying the following:

    "domain names must contain at least two dots (.), hence 'localhost' is invalid and the browser will refuse to set the cookie! instead for localhost you should use false."

    This is true, and your app will work if you use setcookie over Zend_Http_Cookie.

    [PHP]
    setcookie('lang', $_GET['lang'], time() + 7200, '/', false);
    [/PHP]

    However, using Zend_Http_Cookie and setting the domain as false returns an error:

    [PHP]
    $cookie = new Zend_Http_Cookie('lang', $_GET['lang'], false, time() + 7200);
    [/PHP]

    [HTML]
    Fatal error: Uncaught exception 'Zend_Http_Exception' with message 'Cookies must have a domain' in C:\wamp\www\ewhq\library\Zend\Http\Cookie.php
    [/HTML]

    Not a huge biggy - but it would be nice for the people developing ZF locally to be able to use the ZF cookie library and all the methods that go with it.

    Aaron

  5. #5
    juggernt is offline Junior Member
    Join Date
    Dec 2007
    Location
    DC/VA
    Posts
    3

    Default

    Aaron-
    Why don't you just set-up a 'local domain' via the hosts file? Since this file is read before DNS, you can make it any domain you want. If you do gothat route, then Zend_Http_* will work fine.
    Of course, you should also set your PHP 'cookie_domain' via the php.ini or .htaccess, etc.

    I was working with these locally last week on a sub-project using ZF v174, so I know it can be done. -

    Jay

  6. #6
    aaron78 is offline Junior Member
    Join Date
    Nov 2008
    Posts
    9

    Default

    Cheers Jay,

    I got around it by just using straight PHP setcookie().

    Yeah I use my host file, but my domains are always like [project].localhost. I could make them fully qualified I guess. I was just curious that ZF's cookie library didn't adhere to PHP standards.

    Must be a reason for it.

    Aaron

Similar Threads

  1. Can Zend connect to a non localhost database?
    By tanso in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 06-15-2010, 08:57 AM
  2. My mailing only work on localhost
    By frost20 in forum Mail, Formats & Search
    Replies: 0
    Last Post: 06-02-2009, 01:18 PM
  3. baseUrl issue - localhost and server
    By snickers in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 04-13-2009, 02:09 PM
  4. Replies: 3
    Last Post: 04-16-2008, 07:17 AM
  5. send mail on localhost
    By amthasija in forum Mail, Formats & Search
    Replies: 1
    Last Post: 12-06-2007, 09:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •