一聚教程网:一个值得你收藏的教程网站

热门教程

php Cannot modify header information - headers already sent by set 解决方法

时间:2022-06-24 23:48:39 编辑:袖梨 来源:一聚教程网

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来解决):

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

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();
?>

热门栏目