当前位置:Gxlcms > PHP教程 > phpCannotmodifyheaderinformation-headersalreadysent_PHP教程

phpCannotmodifyheaderinformation-headersalreadysent_PHP教程

时间:2021-07-01 10:21:17 帮助过:21人阅读

本文章介绍了多种关于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来解决):

代码如下

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632237.htmlTechArticle本文章介绍了多种关于php Cannot modify header information - headers already sent by set 解决方法 ,有需有的朋友可以参考一下。 在 php 配置文件 php.ini...

人气教程排行