2010-03-02 19 views
3

首先,我絕不是PHP的新手,或者發送頭文件。但是,我收到以下錯誤:什麼可能會導致標題已被髮送,我將如何跟蹤它?

Warning: Cannot modify header information - headers already sent in /var/www/oraviewer/download/scripts/start.inc on line 30 

Warning: Cannot modify header information - headers already sent by (output started at /var/www/oraviewer/download/scripts/start.inc:30) in /var/www/oraviewer/download/scripts/start.inc on line 31 

Warning: Cannot modify header information - headers already sent by (output started at /var/www/oraviewer/download/scripts/start.inc:30) in /var/www/oraviewer/download/scripts/start.inc on line 32 

3錯誤,因爲我試圖發送3個標頭。

我搜遍了每一個文件,檢查它們是否有可能發送標題,換行符,文本等等,而且什麼都沒有。

我習慣了這種錯誤,告訴你打印的第一位來自哪裏(請參閱第二個錯誤以瞭解我的意思),但第一位不告訴我任何事情。

據我所知,自從我上次讓他們工作並使用備份副本後,這些文件都沒有發生任何變化,他們工作正常。不幸的是,如果我將它們替換爲備份文件,問題依然存在。我會發布這些文件,但其中大約有六打,達到了幾百行。

所以,我的主要問題:什麼可能導致這種情況,我將如何追蹤它來自哪裏?

編輯:3條線在30-32,whcih是特定的頭文件被打印

header('Content-Type: application/octet-stream'); 
header('Content="text/plain;charset=ISO-8859-1"'); 
header('Content-Disposition: attachment; filename="'.$fileName.'"'); 

如果我評論一出,誤差在下一之一啓動,所以我知道它的這些東西面前。

在getExtract.php文件start.inc之前的代碼:

<?php 
include_once "start.inc"; 

的start.inc文件:

<?php 
$extract = $_GET['extract']; 
$debug = $_GET['debug']; 
include "../../lib/conf.inc"; 
include $mainsitedir."/lib/db_connect.inc"; 
include $mainsitedir."/lib/utils.inc"; 
include "../queries/get_output_file_name.php"; 

$db_link = connect_db(); 
$query = "SELECT * FROM extract_wxo_list WHERE extract_id='{$_GET['extract']}'"; 
$file = db_get_row(db_query($db_link, $query)); 
$fileName = $file['OUTPUT_FILE_NAME']; 

if (!empty($_GET['versiondate'])) { 
    $sql = "SELECT * FROM version_history WHERE version_start_date = '{$_GET['versiondate']}'"; 

    $vquery = db_query($db_link, $sql); 
    if ($vrow = db_get_row($vquery)) { 
     $splitName = preg_split("/[.]/", $fileName, 2); 
     $fileName = $splitName[0].'_'.str_replace(".", "", $vrow['VERSION']).'.'.$splitName[1]; 
    } 
} 

if ($_GET['debug']) { 
    echo "$fileName<br /><pre>"; 
} else { 
    header('Content-Type: application/octet-stream'); 
    header('Content="text/plain;charset=ISO-8859-1"'); 
    header('Content-Disposition: attachment; filename="'.$fileName.'"'); 
} 
date_default_timezone_set('UTC'); 
?> 

4包括靠近頂部是在其他幾個文件相同。他們也使用類似但不那麼通用的方式標題,所以我可以將它們排除在外。

+0

你可能會在'/var/www/oraviewer/download/scripts/start.inc:30'上發帖嗎?3個錯誤都說輸出開始了嗎? – animuson

+0

看起來像第30行的/var/www/oraviewer/download/scripts/start.inc。 –

+0

嘗試在不同的地方使用obstart來做同樣的事情?當你刪除這3行時會發生什麼? –

回答

1

檢查您是否在<?php之前留下了空格或嘗試使用ob_start();和ob_end_flush();

<?php 
ob_start(); //Starts output puffer 
echo "texttest"; 
if($bala==1) { 
header("location:http://www.testdomain.org"); 
} 
ob_end_flush(); //ends output puffer 
?> 
+0

這幾行給出了這個嘗試,並且指出了錯誤發生的位置。我在另一個函數中有一個ob_flush(),我沒有意識到這個函數正在被調用,而這只是傾倒而已。修正了它的調用方式,現在我的標題再次工作。謝謝! – Tarka

0

查看/var/www/oraviewer/download/scripts/start.inc第30行。這很可能是對瀏覽器的迴應,打印,刷新或轉儲內容。

+0

忘了提及,這些是我試圖打印的標題。我用完整的start.inc更新了這個問題,並突出顯示 – Tarka

相關問題