PHP警告:无法修改标头信息

 收藏

当我尝试“登录”我正在创建的php成员系统时,我一直收到此错误消息。

警告:无法修改标头信息-第21行的C:\ xampp \ htdocs \ acrd \ login.php中已经发送过的标头(输出从C:\ xampp \ htdocs \ acrd \ includes \ header.php:24开始)

这是21行

header('Location: index.php');

这是我的代码。请帮忙!

    <?php
    include 'core/init.php';
    include 'includes/overall/header.php';

    if (empty($_POST) === false) {
        $username = $_POST['username'];
        $password = $_POST['password'];

        if (empty($username) === true || empty($password) === true) {
            $errors[] = 'You need to enter a username and password.';
        } else if (user_exists($username) === false) {
            $errors[] = 'We cannot find that username. Have you registered?';
        } else if (user_active($username) === false) {
            $errors[] = 'You have not activated your account.';
        } else {
            $login = login($username, $password);
            if ($login === false) {
                $errors[] = 'That username/password combination is incorrect.';
            } else {
                $_SESSION['user_id'] = $login;
                header('Location: index.php');
                exit();
            }
    }
        print_r($errors);
    }
    include 'includes/overall/footer.php';
    ?>
回复
  • 冼华美 回复

    我将其添加到login.php文件的顶部,但它不起作用:(

  • Gosse 回复

    我终于明白了!谢谢。我必须放入<?php ob_start();?> 也许是因为我正在使用Dreamweaver。

  • 胡了~ 回复

    在顶层文件中调用ob_start

    ob_start();