Home  >  Article  >  php教程  >  Warning: Cannot modify header information - headers already sent by

Warning: Cannot modify header information - headers already sent by

WBOY
WBOYOriginal
2016-05-25 16:52:181911browse

如果在执行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. 用输出缓存来解决:

<?php
... HTML codes ... 

... PHP codes ... 
header ("Location: ...."); 
ob_end_flush(); 
?>

               
               

永久地址:

转载随意~请带上教程地址吧^^

Statement:
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