in reply to Sending a cookie header and HTML output

You can send multiple headers. A call to header() with multiple parameters prints multiple headers to the browser. Calling
print header(-type=>'text/html', -cookie=>$your_cookie ...)
would actually print out
Content-type: text/html\n Cookie: $your_cookie\n\n
To give you a better answer than you can print out more than one header, I need to see some sample code.

Replies are listed 'Best First'.
Re: Re: Sending a cookie header and HTML output
by Anonymous Monk on Jun 24, 2003 at 14:46 UTC

    Just thought of another problem: say I'm authenticating a user, I check for a cookie containing a session ID, if the cookie doesn't exist I check for login parameters from a form. If the login is valid, I want to set a cookie containing a session ID. I have all the preceeding in a subroutine which I call, then later I will print out an HTML document (say: a welcome message) - which is the best way to handle this? Should I send the cookie & header, let the script finish running then send the HTML (the actual data, not the header), or should I return the cookie to the calling code and send it only right before the HTML? Thanks.

      I prefer to send all of my output(including the headers) at the end of the script, after all of the processing has been done. The reason I do it that was is because if an error occurs during processing, you don't have an half loaded page, then an error. I can just scrap all of the legitiment output and display the error message.