http://qs321.pair.com?node_id=263403


in reply to Re: Re: Problem setting cookie using CGI::Cookie
in thread Problem setting cookie using CGI::Cookie

Yes, that will cause a problem if you print it before the header. The header must come first. The cookie must be in the header. If you print anything else first and the web browser accepts the cookie, it's broken.

Your web server may add headers automatically if you don't print the headers first, but your cookie won't be set if that happens. You get one chance to print the HTTP header and the cookie must be in that header.

I'm being very explicit here because this trips up a lot of people.

As far as the domain issue, you may need to add a trailing period. I seem to recall that CGI::Cookie checks to see if the domain name contains two periods. Does it work better with example.com.?

Replies are listed 'Best First'.
Re: Re: Re: Re: Problem setting cookie using CGI::Cookie
by kutsu (Priest) on Jun 05, 2003 at 16:45 UTC

    The cookie is only sent if the username is correct and ,if it is, does print before the header. Maybe my script doesn't show that well?

    "Pain is weakness leaving the body, I find myself in pain everyday" -me