代码之家  ›  专栏  ›  技术社区  ›  Tarka user370305

是什么原因导致邮件头已经发送,我该如何跟踪它?

  •  3
  • Tarka user370305  · 技术社区  · 15 年前

    首先,我决不是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个邮件头。

    我搜遍了所有包含的文件,检查它们是否有可能发送标题、换行符、文本等,但什么都没有。

    我已经习惯了这种错误告诉你第一个打印点是从哪里来的(请看后面的两个错误来了解我的意思),但第一个错误什么也没告诉我。

    据我所知,这些文件都没有改变,因为我上次让他们工作,并使用备份副本,他们工作得很好。不幸的是,如果我用备份文件替换它们,问题仍然存在。我会把这些文件寄出去,但大约有六份,总共有几百行。

    所以,我的主要问题是:这可能是什么引起的,我如何追踪它是从哪里来的?

    编辑:30-32处的3行,它们是要打印的特定页眉

    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个include是相同的。它们也以类似但不太通用的方式使用标题,因此我可以排除它们的原因。

    2 回复  |  直到 15 年前
        1
  •  1
  •   streetparade    15 年前

    检查之前是否留下空白 <?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
    ?>
    
        2
  •  0
  •   Andy Ali    15 年前

    /var/www/oraviewer/download/scripts/start.inc 第30行。这很可能是回声、打印、刷新或将某些内容转储到浏览器中。