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条)

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”