Home > php教程 > php手册 > php Cannot modify header information

php Cannot modify header information

WBOY
Release: 2016-06-13 09:56:02
Original
1081 people have browsed it

本文章介绍了多种关于php Cannot modify header information - headers already sent by set 解决方法 ,有需有的朋友可以参考一下。

在 php 配置文件 php.ini 中将 output_buffering 设置为 On。开启即可。

output_buffering = On  

-------------------------------
All or nothing, now or never.


有以下几种解决方法:

1. Blank lines (空白行):
Make sure no blank line after of the calling php script.
检查有 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。

 

2. Use exit statement (用exit来解决):

 代码如下 复制代码
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit();

 Use Javascript (用Javascript来解决):

 代码如下 复制代码
echo "<script> self.location("file.php");</script>"; ?>

Since it's a script, it won't modify the header until execution of Javascript.
可以用Javascript来代替header。但是上面的这段代码我没有执行成功... 另外需要注意,采用这种方法需要浏览器支持Javascript.

3b. Use output buffering (用输出缓存来解决):

 代码如下 复制代码

... HTML codes ...
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template