2012-11-09 121 views
-4

可能重複:
PHP Fix Warning: Cannot modify header information - headers already sent
「Warning: Headers already sent」 in PHP如何解決'警告:無法修改標題信息'錯誤?

我有一個不錯的網站,非常完美。第一頁是header.php文件,第一行是:

<?xml version="1.0" encoding="utf-8"?> 

有一天我開始說語法錯誤行1。所以我做了網絡上的一些研究,改變了第一行到這一點:

<?php echo '<?xml version="1.0" encoding="utf-8"?>' ?> 

解析錯誤問題消失了。但隨後另一個問題出現了:

Warning: Cannot modify header information - headers already sent by (output started at /Volumes/raid/Web/Sites/*******.com/header.php:1) 

所以我決定從代碼中刪除這個第一行(和說實話,我不知道什麼是它的目的)。然後,一個新的錯誤出現:

Warning: Cannot modify header information - headers already sent by (output started at /Volumes/raid/Web/Sites/*******.com/header.php:25) 

這裏的地方我找不到任何錯誤代碼(在行尾沒有空格,肯​​定)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd"> 
<html lang="fr" dir="ltr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <link href="/css/bootstrap.css" rel="stylesheet"> 
    <link href="/css/style.css" rel="stylesheet"> 
    <link type="image/x-icon" href="./img/lions_icon" rel="icon"> 
    <link type="image/x-icon" href="./img/lions_icon" rel="shortcut icon"> 
    <link href="/css/jquery.ui.all.css" rel="stylesheet"> 
    <title>Lions</title> 
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> 
    <script src="/js/jquery.js"></script> 
    <script src="/js/jquery-1.8.2.js"></script> 
    <script src="/js/jquery.ui.core.js"></script> 
    <script src="/js/jquery.ui.widget.js"></script> 
    <script src="/js/jquery.ui.datepicker.js"></script> 
    <script src="/js/bootstrap.js"></script> 
    <script> 
    $(function() { 
     $("#date").datepicker(); 
     $("#date").datepicker("option", "dateFormat", "yy-mm-dd"); 
     }); 
    </script> 
</head> 
<?php 
// beggining of the php code, 
.... 
?> 
<body> 
... 

線25是一個地方PHP開始。

回答

0

您的代碼中的某處正在使用header()如果您在該代碼之前輸出任何內容,您的頁面將返回該錯誤。另外請確保您在<?php之前和?>之後沒有空格,那麼在發送header();之前,頁面會以html形式返回空格。

+0

這件事是我不輸出任何東西之前的頭()和錯誤說輸出發生25行或1行,如果我保持我的第一行(你可以看到在線程中)。 –

0

在做任何事情之後,您無法發送標頭。如果您放置第1行使用的標題功能,則問題已修復;)。

0

好這個問題您北京時間您執行

<?php echo '<?xml version="1.0" encoding="utf-8"?>' ?> 

可能你獲得一個E_NOTICE或E_WARNING前已數據發送給瀏覽器。您是否嘗試激活錯誤報告?

error_reporting(-1); ini_set('display_errors', 1); 
0

錯誤是在php標籤內,可能你使用的是像Header Location之類的東西。在html中沒有錯誤。

0

(如果你使用的PHP框架==真)
{
這種情況可能存在,當你有一個像例如一些輸出呼應控制器。
}

相關問題