【发布时间】:2013-01-15 06:27:23
【问题描述】:
我的日志文件中不断出现此错误:
[15-Jan-2013 00:50:04] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/usr/public_html/display.php:1) in /home/usr/public_html/display.php on line 17
所以我查看了第一行的页面,我没有看到任何可能发送标题的地方。
display.php:
<?PHP
require './err/errhandler.php';
require './assets/display.php';
require './assets/excrate.php';
$mysql_host = "sqlhost";
$mysql_database = "db";
$mysql_user = "user";
$mysql_password = "password";
$name = $_REQUEST["q"];
$type = $_GET["s"];
$timeperiod = $_POST["tp"];
$currency = $_POST["c"];
if(isset($currency)){
setcookie("prefCur", $currency, time()+60*60*24*30*12, "/");
$_COOKIE["prefCur"] = $currency;
} else {
if(!isset($_COOKIE["prefCur"])){
setcookie("prefCur", "usd", time()+60*60*24*30*12, "/");
$_COOKIE["prefCur"] = "usd";
}
}
...
errhandler.php:
<?PHP
ini_set('display_errors', false);
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__) . '/_err.log');
ini_set('output_buffering', 'on');
display.php:
<?PHP
function strip_name($name)
{
return preg_replace('/\s\([a-zA-Z 0-9]*\)/', '', preg_replace('/[0-9%]+\s/', '', str_replace(":", "", str_replace("-H", "-h", $name))));
}
excrate.php:
<?PHP $eur = 0.747807; $gbp = 0.621828; $rub = 30.227148;
然后我想知道是不是我的主机附加了一个 php 文件,所以将我的 htaccess 更改为:
php_value auto_prepend_file none
php_value auto_append_file none
Options +FollowSymLinks
...
我仍然收到声称标头已发送的错误消息。我现在很难过。第一行的标头在哪里发送?我什至无法启用输出缓冲,因为它在第一行!
编辑:<?PHP 之前绝对没有任何内容,即使打开输出缓冲,它也不起作用。它只是从第 17 行下移到第 18 行。
【问题讨论】:
-
你其他文件的内容是什么?
-
$_COOKIE["prefCur"] = $currency;是有效的代码吗? -
你的 php 之前甚至没有空格或换行符?甚至是普通的html?特别是在您的包含文件中?
-
所需文件有输出代码吗?还是空格?
-
检查所有包含的文件中是否存在 UTF-8 BOM。
标签: php http-headers output-buffering