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

I'm not sure if this is even possible, but I wanted to know if a cookie could be set after a print Content-Type.
print "Content-Type: text/html\n"; my $cookieID = new CGI::Cookie(-name => 'MerchID', -value => $id); print "Set-Cookie: $cookieID\n";
The thing is the Content-Type is being called in another script (which is calling my script) which I can't change, so I'm stuck. Is there a way to disable the print header until after the cookie is set? I'm fairly new at this cookie thing, so any suggestions would be greatful!

Replies are listed 'Best First'.
Re: Set Cookie Question
by ikegami (Patriarch) on Sep 02, 2004 at 17:00 UTC

    Make sure there isn't a blank line anywhere between the Content-Type and the Set-Cookie. The blank line marks the end of the headers and the start of the content.

    If I remember correctly (but it's been years), Set-Cookie SHOULD -- as opposed to MUST -- appear after Content-Type, meaning it's ok to put it before the Content-Type.

Re: Set Cookie Question
by amonroy (Scribe) on Sep 02, 2004 at 16:16 UTC
    What about setting the cookie with JavaScript?
      I was able to find a place above the content type in another script that allowed it to work. I'm sorry for the bother. Thanks for replying.