Warning:cannot Add header information-headers already sent in
When output_buffering is enabled, PHP does not send HTTP headers when the script sends output. Instead, it enters the output through the pipeline (pipe) into the dynamically incremented cache (only PHP 4). 0, it has a centralized output mechanism). You can still modify/add headers, or set cookies, because the header is not actually sent. When all scripts are terminated, PHP automatically sends the HTTP header to the browser and then sends the contents of the output buffer.
First of all: How did this error arise? Let's take a look at how PHP handles HTTP header output and body output.
When the PHP script starts executing, it can send header (header) and principal information at the same time. Header information (from the header () or Setcookie () function) is not sent immediately, instead, it is saved to a list. This allows you to modify the header information, including the default headings (such as content-type headings). However, once the script sends any non-caption output (for example, using HTML or print () calls), PHP must first send all headers and then terminate the HTTP header. And then continue sending the principal data. From this point on, any attempt to add or modify header information is disallowed and sends one of the above error messages.
Well, then we'll fix it:
Stupid method: Do not show the error warning all!
The concrete method does not say the plan ^_^
Solution:
1 is suitable for editing PHP with permission. INI's People
Open PHP. INI file (you try to test your PHP better than I do). Where is the INI), find
output_buffering = change to On or any number. If it is IIS6, be sure to ON, otherwise your PHP efficiency will be very slow.
2 Use a virtual host, you cannot edit PHP. INI, how to do?
Simple:
Create one in the root directory of your space. htaccess file, which reads as follows:
AllowOverride All
Php_flag output_buffering on
The unfortunate situation is: still not? All pages are not displayed?
Well, you can call and scold a space trader, and then let him give you Apache's. htaccess allowoverride Open
3 in the PHP file to solve
Ob_start ()
Enable the output buffering mechanism. Output Buffering supports multiple tiers-for example, the Ob_start () function can be called multiple times.
Ob_end_flush ()
Sends output buffer (output buffering) and disables the output buffering mechanism.
Ob_end_clean ()
Clears output buffer but does not send, and disables output buffering.
Ob_get_contents ()
Returns the current output buffer to a string. Allows you to process any output that the script emits.