如果在执行php程序时看到这条警告:”Warning: Cannot modify header information – headers already sent by ….”
有以下几种解决方法:
1. 空白行:
检查有<?php … ?> 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。
2. 用exit来解决:
在header后加上exit();
header (“Location: xxx”);
exit();
3. 用输出缓存来解决:
<?php ob_start(); ?>
… HTML codes …
<?php
… PHP codes …
header (“Location: ….”);
ob_end_flush();
?>