0

我收到一个错误,指出:

警告:无法修改标头信息 - 第 66 行 /home/content/21/10941021/html/register.php 中的标头已由(输出开始于 /home/content/21/10941021/html/index.php:4)发送

我想我需要放一个 ob_start() 来让缓冲正常工作,但我无法让它下来。我的问题所在的代码包括:

<div class="lower-body">
<div class="left-lower">Create an account</div>
<div id="account-first">
<?php ob_start();
if (isset($_GET['success']) && empty($_GET['success'])){
    echo 'You\'ve been registered successfully!';
    echo 'Please check email and activate account!'; 
}else {

if(empty($_POST) === false && empty($errors) === true){
    $register_data = array(
        'firstname' => $_POST['firstname'],
        'lastname'  => $_POST['lastname'],
        'username'  => $_POST['username'],
        'password'  => $_POST['password'],
        'email'     => $_POST['email'],
        'zipcode'   => $_POST['zipcode']
        );

    register_user($register_data);
    header('Location: register.php?sucess');
    exit();
} else if(empty($errors) === false){
    echo output_errors($errors);
    }
}
ob_end_flush();?>

然后第 4 行是这样的:

<?php
ob_start();
include 'includes/overall/head.php';
?>

有任何想法吗?非常感谢!

4

1 回答 1

0

header('Location: register.php?sucess');应该在任何输出之前echo

编辑1:ob_start();在php代码的开头和ob_end_flush();结尾使用,应该可以解决问题。

编辑2:使用这个

<?php ob_start(); ?>
<div class="lower-body">
<div class="left-lower">Create an account</div>
<div id="account-first">
<?php
...
...
ob_end_flush();
?>
于 2013-05-02T21:26:57.983 回答