无法修改标题信息 [英] Cannot modify header information

查看:108
本文介绍了无法修改标题信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

已由PHP发送的标题

我收到以下来自下面的代码的错误,我不完全确定为什么。如果你能告诉我如何解决这个问题,那会很棒。

I am getting the following error from the following code, and I am not entirely sure why. If you could tell me how to fix it, that would be great. Thanks in advanced.

警告:无法修改标题信息 - 标题信息已经由第45行的(输出开始于...)发送。

Warning: Cannot modify header information - headers already sent by (output started at...) on line 45.

<?php


    // Initialization
    $conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
    mysql_select_db(DB_NAME, $conn);

    // Error checking
    if(!$conn) {
        die('Could not connect ' . mysql_error());
    }

    // Localize the GET variables
    $ref  = isset($_GET['ref']) ? $_GET['ref'] : "";

    // Protect against sql injections
    // Insert the score
    $retval = mysql_query("INSERT INTO $table(
            site
        ) VALUES (
            '$ref'
        )",$conn);

    if($retval) {
        echo "Successfull";
    } else {
        echo "Unsuccessfull " . mysql_error();
    }

    mysql_close($conn);
?>
<?php
$url = $_GET['url'];
    $loc = 'Location: '. $url;
    header($loc);
exit;
?>


推荐答案

信息到头部之前的浏览器。

Take out the echo calls, you can't send information to the browser before the headers.

您可以尝试这样的事情,以显示是否发生错误:

You can try something like this to still show if an error happens:

if(!$retval) {
    echo "Unsuccessfull " . mysql_error();
}

这篇关于无法修改标题信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆