This article introduces various solutions to php Cannot modify header information - headers already sent by set
, friends who need it can refer to it.
Set output_buffering to On in the php configuration file php.ini. Just turn it on.
output_buffering = On
----------------------------------
All or nothing, now or never.
There are several solutions:
1. Blank lines:
Make sure no blank line after of the calling php script.
Check that there are no blank lines after , especially include or require files. Many problems are caused by these blank lines.
2. Use exit statement (use exit to solve):
The code is as follows
代码如下 |
复制代码 |
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit(); |
|
Copy code
|
Use exit after header statement seems to help some people
代码如下 |
复制代码 |
echo "<script> self.location("file.php");</script>"; ?>
|
Add exit(); after the header
header ("Location: xxx");
exit();
代码如下 |
复制代码 |
... HTML codes ...
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?> |
Use Javascript (use Javascript to solve): |
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. But I did not execute the above code successfully... Also note that using this method requires the browser to support Javascript.
3b. Use output buffering (use output buffering to solve):
The code is as follows
|
Copy code
|
... HTML codes ...
... PHP codes ...
header ("Location: ....");
ob_end_flush(); |
|
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn