PHP 标头已发送

2022-01-11 00:00:00 header php

可能重复:
已由 PHP 发送的标头

得到以下错误:

"Warning: Cannot modify header information - headers already sent by (output started at..."

对于以下行:

echo '<center>Current Time is '. gmdate("H:i A") . ' GMT (Greenwich Mean Time or UTC)<br />';

如果我将其注释掉,它只会在下一个 echo 语句中抛出错误.思考为什么 PHP 如此讨厌我的 echo 语句?

If I comment it out it just throws up the error at the next echo statement. Thoughts on why PHP hates my echo statements so much?

这是我在 HTML 底部的包含:

Here is my include toward the bottom of the HTML:

<div id="saveCanForm" width="100%">
<?php include('savereport.php'); ?>
</div>

推荐答案

问题不在于 echo 语句.看起来您在文件的稍后位置有一个 header 调用,但是一旦输出任何文本,您就无法发送标题.您可以将标头移动到脚本的开头,也可以使用输出缓冲.

It's not the echo statements that are the problem. It looks like you have a header call somewhere later in the file, but you can't send headers once you output any text at all. You could either move the headers to the beginning of the script or alternatively use output buffering.

相关文章