OK, here's my 2p worth:
===
Q. Why am I getting the error message 'Headers already sent'?
A. PHP produces this error message when you try to set a header for a web
page after you have already started sending out the content of the page.
Web content is always delivered with a few headers at the top, ending with a
blank line. For example, a web page might start like this:
[color=blue]
> HTTP/1.1 200 OK
> Date: Tue, 01 Mar 2005 12:00:00 GMT
> Content-Type: text/html
>
> <html>
> <body> ... etc...[/color]
Once you have started sending the content of a document, you can't add any
more headers because they won't appear at the top.
To get round this problem, use PHP's output control functions to buffer the
output before it is sent. For example, you can generate a "Content-Length"
header as follows:
[color=blue]
> <?php
>
> ob_start(); // Turn on output buffering
>
> // Create your web page/jpeg file/whatever here
> echo "<html><bod y> ... ";
>
> // Generate a "Content-Length" header
> $clen = ob_get_length() ;
> header("Content-Length: $clen");
>
> // Now send the buffered content
> ob_flush();
>
> ?>[/color]
--
phil [dot] ronan @ virgin [dot] net
===
Q. Why am I getting the error message 'Headers already sent'?
A. PHP produces this error message when you try to set a header for a web
page after you have already started sending out the content of the page.
Web content is always delivered with a few headers at the top, ending with a
blank line. For example, a web page might start like this:
[color=blue]
> HTTP/1.1 200 OK
> Date: Tue, 01 Mar 2005 12:00:00 GMT
> Content-Type: text/html
>
> <html>
> <body> ... etc...[/color]
Once you have started sending the content of a document, you can't add any
more headers because they won't appear at the top.
To get round this problem, use PHP's output control functions to buffer the
output before it is sent. For example, you can generate a "Content-Length"
header as follows:
[color=blue]
> <?php
>
> ob_start(); // Turn on output buffering
>
> // Create your web page/jpeg file/whatever here
> echo "<html><bod y> ... ";
>
> // Generate a "Content-Length" header
> $clen = ob_get_length() ;
> header("Content-Length: $clen");
>
> // Now send the buffered content
> ob_flush();
>
> ?>[/color]
--
phil [dot] ronan @ virgin [dot] net
Comment