Mr. Newb has asked for the wisdom of the Perl Monks concerning the following question:

Monks - I seem to be unable to read a cooke -  CGI::Cookie->fetch returns nothing. However, I've checked my browser, and there most definitely are some cookies there. What's also weird is that there is another script on my site, which is able to read the cookie. Possible causes? Should I be checking with the browser, the webserver (apache), or the perl? I've already ruled out the possibility of miswritten cookies - I wrote the cookie myself! - and am able to access it other places, too. Thanks!

Replies are listed 'Best First'.
Re: Cookie Reading Problem
by rnewsham (Curate) on Jun 27, 2013 at 06:39 UTC

    Have you checked the host value for the cookies? For example are the cookies created on http://www.foo.com/ and your script running on http://foo.com or vice-versa.

      Hmmm.. that might be the problem. Does that make a difference? I can't remember at the moment, but I think i did not specify the domain name in the cookie when I set it. Does the CGI module automatically set it, if you don't specify one?

        Below is an extract from the documentation for CGI which should clear things up. See the full documentation at HTTP COOKIES for full details.

        " a domain This is a partial or complete domain name for which the cookie is valid. The browser will return the cookie to any host that matches the partial domain name. For example, if you specify a domain name of ".capricorn.com", then the browser will return the cookie to Web servers running on any of the machines "www.capricorn.com", "www2.capricorn.com", "feckless.capricorn.com", etc. Domain names must contain at least two periods to prevent attempts to match on top level domains like ".edu". If no domain is specified, then the browser will only return the cookie to servers on the host the cookie originated from."

Re: Cookie Reading Problem
by Anonymous Monk on Jun 27, 2013 at 04:01 UTC

    Possible causes?

    You didn't redirect after sending cookies the first time, thus there are no cookies yet on the server