This article introduces a variety of solutions for php Cannot modify header information-headers already sent by set. If you need it, refer to it.
Set output_buffering to On in the php configuration file php. ini. Enable.
Output_buffering = On
-------------------------------
All or nothing, now or never.
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 ):
| The Code is as follows: |
Copy code |
Use exit after header statement seems to help some people
Add exit () after the header ();
Header ("Location: xxx ");
Exit (); |
Use Javascript ):
| The Code is as follows: |
Copy code |
<? 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. However, the above Code is not successfully executed... You need to note that using this method requires the browser to support Javascript.
3b. Use output buffering (solved by the output cache ):
| The Code is as follows: |
Copy code |
<? Php ob_start ();?>
... HTML codes...
<? Php
... PHP codes...
Header ("Location :....");
Ob_end_flush ();
?> |