Warning: Cannot modify header information - headers ...问题

Zen Cart的安装、设置、升级讨论和使用技巧交流

版主: 赞拓拓, shaning, 美拓拓

Warning: Cannot modify header information - headers ...问题

帖子thisuc » 2010-06-08 10:19

请教各位:

网站出现以下问题:
主页必须在 require('includes/application_top.php')前面或者application_top.php涉及到的文件中加入echo语句,才可以显示内容。
如果去掉就出现<dfj(dfj代表乱码),其它空白。打开调拭程序后,只看到一些notice之类的提示。

加入echo语句后,主页可以显示,但进入产品购物车就出现
Warning: Cannot modify header information - headers already sent by ....
其它空白。


在网上找到以下处理方法:
If you got this message: "Warning: Cannot modify header information - headers already sent by ...."
如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ...."

Few notes based on the following user posts:
有以下几种解决方法:

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

2. Use exit statement (用exit来解决):
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit();

3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it'll said "Warning: Cannot modify header information - headers already sent by ...." Basically anytime you output to browser, the header is set and cannot be modified. So two ways to get around the problem:

3a. 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 (用输出缓存来解决):
<?php ob_start(); ?>
... HTML codes ...
<?php
... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>


但我试过这些方法,检测过提示涉及到的文件,还是同样的问题。

请问各位高手,这种情况怎么解决呢?
另外,我用的是godaddy免费空间,这会不会是空间问题呢?因为我在本地测试的没有任何问题,传到空间就出问题了。
小弟先谢了!
thisuc
普通会员
普通会员
 
帖子: 27
注册: 2009-12-24 9:27

Re: Warning: Cannot modify header information - headers ...问题

帖子thisuc » 2010-06-13 15:04

已经解决了,
是godaddy免费空间的问题。
我换了个空间,同样的源文件,一切正常!
thisuc
普通会员
普通会员
 
帖子: 27
注册: 2009-12-24 9:27


回到 安装设置

 


  • 相关话题
    回复总数
    阅读次数
    最新文章

在线用户

正在浏览此版面的用户:Majestic-12 [Bot] 和 4 位游客