“已发送标头”错误

时间:2014-02-07 00:53:59

标签: php header

我已经在这个项目上工作了三个月(在Windows上使用PHP 5.4.12),昨天我终于决定它已经准备好上传了。

我的托管服务器在Linux上运行PHP 5.3.28,一旦我将所有文件放到网站上它根本不起作用。主要问题与header函数有关,只要用户输入有效的用户名和密码组合,就会调用该函数。

(我知道有很多关于这类问题的帖子,但到目前为止我无法利用它们)。

以下是代码:

<?php
function login() {
    //// Getting employee number

    if (empty($_POST['field'])) {
        $err[] = "missing field!";
    } else {
        $field = mysqli_real_escape_string($dbc, trim($_POST['field']));
    }

    //// same thing for the password

    //// If there are no errors go with the query

    if (empty($err)) {
        go with the query and get the results
        $count = mysqli_stmt_num_rows($stmt); // there must be 1 and only 1 user
        if ($count == 1) {
            session_start();
            header("location: /members/home.php"); * * * * * * * * * * * * * * * * * * * * * * *
        } else {
            echo 'User not found!';
            mysqli_stmt_close($stmt);
            mysqli_close($dbc);
        }
    }
} else {
    show the errors
}

请注意不匹配的括号,我粗暴地缩短了代码。我在index.php页面中使用require函数要求此文件,并将表单操作设置为"")。

我已经读过在header函数之前没有任何输出,但我不知道如何换一种方式以免导致"header already sent..."错误。我意识到太晚了,因为我启用了ob,所以它在本地工作。现在托管公司为我启用了ob,但它仍然无效。

有没有办法让它在没有重大编码的情况下工作?

0 个答案:

没有答案
相关问题