binner has asked for the wisdom of the Perl Monks concerning the following question:

For the longest time, I thought that I must be doing something wrong when using cookies. My code works with Netscape (and Mozilla), but not with Opera or IE. I've noticed that Opera only accepts the cookie 'periodically', while Netscape accepts it every time. I can then read the cookie back from a Netscape browser, but never from Opera or IE. I've debugged the actual HTTP transaction, and as far as I can tell, the format is correct (including proper newlines). I've also tried multiple ways of setting the cookie and reading it (from manual to CGI::Cookie, and HTTP_COOKIE to CGI::Cookie). Has anyone else had a similar problem, or am I still missing something? Here is the code that I use to write, and then read my cookie:

Set:
$cookie = cookie (-name => 'admissions', -value => 'true', -expires => '+10m', -path => '/admissions'); my ($site) = './cook.cgi'; print redirect (-cookie => $cookie, -url => $site);

Get:
my (%cookies) = fetch CGI::Cookie; #now iterate thru hash

Thanks for your help... -Ben

Replies are listed 'Best First'.
Re: More about cookies
by Ovid (Cardinal) on Aug 21, 2001 at 23:18 UTC

    You may wish to repost this to Seekers of Perl Wisdom as there is a lot to speculate about here.

    First, are you using IIS? IIS has a known bug in versions 3, 4, and 5 don't allow you to send a cookie with a redirect. I don't think this is the issue as you mentioned that Netscape works with this.

    Try taking out the 'path' for testing. The browser will assign a default path for you. If your development server has a different path, you will have a problem (this also happens with domains). Is your path the path that the cookie will really be returned to? Is the case the same? I've never tested it, but it's possible that if you have a different case in your path, some browsers may be case-insensitive while others aren't.

    Also, try using an absolute URL instead of a relative one. From the CGI docs:

    One hint I can offer is that relative links may not work correctly when you generate a redirection to another document on your site. This is due to a well-intentioned optimization that some servers use. The solution to this is to use the full URL (including the http: part) of the document you are redirecting to.
      You may wish to repost this to Seekers of Perl Wisdom

      Ovid! I expect you to know better. If a question gets posted to Cat Q+A and should instead be in SoPW, then one of QandAEditors can simply move it. (:

              - tye (but my friends call me "Tye")