2013-01-15 36 views
-1

可能重复:
Headers already sent by PHP标题已发送?...在​​哪里?

我不断收到这个错误在我的日志文件:

[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

+0

你的其他文件的内容是什么? – Daedalus

+0

'$ _COOKIE [“prefCur”] = $货币;'是那个有效的代码? – Class

+0

甚至没有你的PHP之前的空白空间或新行?甚至纯html?特别在你的包含文件中? –

回答

0

简单的写这些代码文件

ob_start(); 
+0

试过了。我将它设置在errhandler.php中: '<?PHP ini_set('display_errors',false); ini_set('log_errors',true); ('output_buffering','on');' – user1965359

+0

您还需要结束输出缓冲'ob_end_flush();'检查这个[**什么是输出缓冲?**](http://stackoverflow.com/questions/2832010/what-is-output-buffering) –

+0

@NullPointer,不一定。输出缓冲区将在** php **执行结束时自行刷新。尽管如此,'ob_end_flush()'是控制它的好方法。 –

0

的顶部取下呼叫setcookie(),并检查输出。只是抛出输出缓冲并不总是最好的选择。如果您包含的任何文件输出任何您称为的任何或任何功能,则会引发任何警告/通知,这些警告/通知将构成设置的标题。

再次,删除setcookie()并从那里去。这是猜测从外部进一步诊断。 :)

+0

如何检查输出? – user1965359

+0

在您的浏览器中测试页面时。重要的是你要向后剥开洋葱层,直到你发现问题。如果你删除了'setcookie()'并看到**没有可见的输出**,我们可以推测我们正在处理一个流氓空间。 –

+0

噢,我试着通过创建另一个页面test.php,但没有任何东西显示在OP中,它在头文件中没有返回任何内容(没有空白,没有任何内容)。流氓空间将在那里? – user1965359

0

由于OP声称他的要求没有结束标签,因此在每个要求的末尾添加?>

+0

[对于仅包含PHP代码的文件,结束标记(“?>”)从不允许。](http://framework.zend.com/manual/1.12/en/coding-standard.php-file-formatting.html) – user1965359

+0

如果我们只写php代码,就不需要结束标签'?>'在文件中.. –

+0

我想我学到了一些新东西。我一直以为你不得不结束这个标签,但我猜你不适用于只有PHP的页面。是否有这个原因。 – Class