During the conversion of the wishing board encoding last night, a page needs to declare the UTF-8 encoding in the head.ProgramA header in. Google: Find several solutions:
If you got this message: "Warning: cannot modify header information-headers already sent ...."
If you see this warning when executing the PHP program: "Warning: cannot modify header information-headers already sent ...."
Few notes based on the following user posts:
There are several solutions:
1. blank lines (blank line ):
Make sure no blank line after <? PHP...?> Of the calling PHP script.
Check whether <? PHP...?> There are no blank lines, especially include or require files. Many problems are caused by these blank rows.
2. Use Exit Statement (Use Exit to solve ):
Use Exit after header statement seems to help some people
Add exit () after the header ();
Header ("Location: XXX ");
Exit ();
3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it'll said "Warning: cannot modify header information-headers already sent .... "Basically anytime you output to browser, the header is set and cannot be modified. so two ways to get around the problem:
3A. use JavaScript (solved using JavaScript ):
<? Echo "<SCRIPT> self. Location (\" file. php \ "); </SCRIPT>";?>
Since it's a script, it won't modify the header until execution of JavaScript.
You can use JavaScript to replace the header. But the above sectionCodeI did not execute successfully... In addition, note that using this method requires the browser to support JavaScript.
3B. Use output buffering (solved by the output cache ):
<? PHP ob_start ();?>
... Html codes...
<? PHP
... PHP codes...
Header ("Location :....");
Ob_end_flush ();
?>
This will save the output buffer on server and not output to browser yet, which means you can modify the header all you want until the ob_end_flush () statement. this method is cleaner than the Javascript since JavaScript method assumes the browser has JavaScript turn on. however, there are overhead to store output buffer on server before output, but with modern hardware I wocould imagine it won't be that big of deal. javascript solution wocould be better if you know for sure your user has JavaScript turn on their browser.
As in the code above, this method is cached when the page is generated, so that the header can be output after the head is output. This method is used to solve the header problem.
4.set output_buffering = on in PHP. INI (enable PHP. output_buffering in ini)
set output_buffering = on will enable output buffering for all files. but this method may slow down your PHP output. the performance of this method depends on which web server you're working with, and what kind of scripts you're using.
This method is the same as 3B in theory. However, This method enables the output cache of all PHP programs, which may affect the PHP Execution efficiency, depending on the server performance and Code complexity