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

I'm trying to set a cookie:
$cookie_out = $q->cookie(-name=>"chek_mail", -value=>$random,-expires=>'+24h'); print $q->header(-cookie=>$cookie_out);
The problem is, the code comes after the standard line:
print "Content-type: text/html\n\n";
So instead of writing a cookie to the hard drive, it prints cookie code in the browser window. Is there a way to shield this cookie code from the print "Content-type: text/html\n\n"; line so as to have the same effect as putting it before the content line. -Lisa.

update (broquaint): title change (was shield from content statement)

Replies are listed 'Best First'.
Re: shield from content statement
by fruiture (Curate) on Nov 17, 2002 at 11:31 UTC

    Just remove that "standard line", for it is both superfluous and wrong (when you're on a UNIX, \n ist really \012, ASCII 10, LF, which is not CRLF as HTTP wants it). The CGI::header function does what you want, and correctly.

    --
    http://fruiture.de
      I have html text in the script, so if i remove the line, i get a server error. -Lisa

        The HTTP-Header must be the _very first_ thing your script sends to STDOUT:

        #somewhere in the beginning of your program # nothing has been sent to STDOUT yet print $cgi->header( -cookie => $your_cookie, -type => 'text/html' );
        --
        http://fruiture.de