簡體   English   中英

如何使ob_start()正常工作

[英]How to get ob_start() working correctly

我收到一個錯誤,指出:

警告:無法修改標頭信息-第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';
?>

有任何想法嗎? 非常感謝!

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();
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM