标头位置在实时服务器上不起作用 [英] Header location is not working on live server

查看:85
本文介绍了标头位置在实时服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册和付款页面。程序流程就像注册>确认>付款。在注册页面进行验证和计算后,需要进入确认页面。

我的代码是

 < ?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;
//验证
$ b $ if($ error< = 0){
//做一些计算
header('location:confirm.php');
}
}
<?php
ob_flush();
?>

控制输入到if($ error <= 0)子句中,但保留在注册页面上。



我尝试了很多方法,例如:

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

而不是

 头( '位置:confirm.php'); 

已移除

  ob_start()和ob_flush()



在header()之后添加exit()

然后进入空白页。



另外尝试使用

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

然后控件进入确认页面,但url似乎是registration.php



但标题('location:confirm.php');在我的本地服务器上工作正常。有人请帮我解决这个问题..有什么替代方式header()。期待你们..谢谢

解决方案

请记住,必须在发送任何实际输出之前调用header正常的HTML标签,文件中的空行或PHP中的空行。使用include或require函数或其他文件访问函数读取代码,并在调用header()之前输出空格或空行是非常常见的错误。使用单个PHP / HTML文件时存在同样的问题。



还要尝试更改标题('Location:confirm.php');
(注意L是资本,因为它在本地服务器上的工作可能是严格php类型的问题,请尝试一次)


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

解决方案

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)

这篇关于标头位置在实时服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆