首页 > 开发 > PHP > 正文

Warning: Cannot modify header information - headers already sent by

2024-05-04 21:56:38
字体:
来源:转载
供稿:网友

如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ....".

有以下几种解决方法:

1. Blank lines (空白行):

,检查 后面没有空白行,特别是include或者require的文件.不少问题是这些空白行导致的。

2. Use exit statement (用exit来解决):在header后加上exit();

header ("Location: xxx");exit();

3.用Javascrīpt来解决:

self.location( file.php );"; ?>

可以用Javascrīpt来代替header。另外需要注意,采用这种方法需要浏览器支持Javascrīpt.

4. 用输出缓存来解决:

  1.  
  2. ... HTML codes ... 
  3. ... PHP codes ... 
  4. header ("Location: ...."); 
  5. ob_end_flush(); 
  6. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表