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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法