in reply to Unwanted appearance of "Content-type..."

What you're seeing is what happens when you call print header twice in one CGI session. You're not doing that only because you're rolling your own with the print "Content-type:..." statement.

The solutions, as I see it are:

I use the later approach when I have to deal with long, complicated code, where I can't tell which paths contain a print header and which don't - and the cookies are set and printed all over the place. (I once had to maintain a piece of code that set several cookies, at various points in the code. Sometimes I came this >< close to shooting the original author).

Replies are listed 'Best First'.
Re: Re: Unwanted appearance of "Content-type..."
by bradcathey (Prior) on May 03, 2004 at 15:12 UTC
    matija, awesome, thanks. Went with your first bullet point:
    if ( $newcookie ) { print $query->header(-cookie=>$newcookie,-type=>'text/html'); } else { print "Content-type: text/html\n\n"; } print $template->output();
    and it worked perfectly. And thanks for the explanation as well. Looks like I need to do some more reading about HTTP protocols.

    —Brad
    "A little yeast leavens the whole dough."
      That issue has nothing to do with the HTTP, it is just that you didn't read the documentation for CGI::header() closely enough. CGI::header() prints *all* the headers for a typical page, including content type.
        Point well taken BUU. I did just that and for anyone watching, the CGI doc on CPAN says:
        Normally the first thing you will do in any CGI script is print out an HTTP header. This tells the browser what type of document to expect, and gives other optional information, such as the language, expiration date, and whether to cache the document. The header can also be manipulated for special purposes, such as server push and pay per view pages.
        print $query->header(-type=>'image/gif', -nph=>1, -status=>'402 Payment required', -expires=>'+3d', -cookie=>$cookie, -charset=>'utf-7', -attachment=>'foo.gif', -Cost=>'$2.00');<div class="pmsig">
        And I am a better monk for it. Thanks.

        —Brad
        "A little yeast leavens the whole dough."