dpk20361 2014-11-05 02:19
浏览 49
已采纳

标头位置无法在实时服务器上运行

I Have one registration and payment page. program flow is like registration > confirmation > payment. After validation and calculation in registration page need to go to confirmation page.
My code is

<?php
ob_start();
session_start();

include("header.php");
include("ini.php");
date_default_timezone_set('Asia/Brunei');
header('Cache-Control: max-age=900');

if (isset($_POST['submit'])) {
    $error = 0;
//validations

if ($error <= 0) { 
//do some calculation
header('location:confirm.php');
}
}
<?php
ob_flush();
?>

Control entered in to if ($error <= 0) clause, but stay on the registration page.

I tried many ways like

 header('location:confirm.php', true, 302);

instead of

header('location:confirm.php');

removed

ob_start() and ob_flush()



add exit() after  header()

then it goes to blank page.

Also try to use

echo '<script type="text/javascript">';
        echo 'window.location.href="confirm.php";';
        echo '</script>';

Then the control goes to confirmation page but url seems to be as registration.php

But header('location:confirm.php'); is working fine in my local server. Anybody please help me to resolve this issue.. Is there any alternate way for header(). Looking forward to you guys.. Thanks

  • 写回答

4条回答 默认 最新

  • dounan4479 2014-11-05 02:54
    关注

    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

    Also try to change header('Location:confirm.php'); (Note L is capital since its work in your local server may be problem with strict php type try this once)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?