Cannot modify header information
之前碰到过,忘了怎么弄的,这次又碰到了,刚设置WP Keyword Link插件,停用的时候就弹出这个错误了 刚想时下有以下几种解决方法:
1. Blank lines (空白行):
Make sure no blank line after <?php … ?> of the calling php scrīpt.
检查有<?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 Javascrīpt (用Javascrīpt来解决):
<? echo “<scrīpt> self.location( file.php );</scrīpt>”; ?>
Since it s a scrīpt, it won t modify the header until execution of Javascrīpt.
可以用Javascrīpt来代替header。另外需要注意,采用这种方法需要浏览器支持Javascrīpt.
3b. Use output buffering (用输出缓存来解决):—本人用这种方法解决的!已证实可以!
<?php ob_start(); ?>
… HTML codes …
<?php
… PHP codes …
header (“Location: ….”);
ob_end_flush();
?>