PHP重定向与自定义页眉 [英] PHP Redirect with Custom Headers

查看:219
本文介绍了PHP重定向与自定义页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个基本的授权系统,我与它挣扎了一下。这里涉及到两个文件 - 的index.php 的login.php 。登录表单是pretty的简单(这里面的index.php ):     

I am writing a basic authorization system and I am struggling with it a bit. There are two files involved - index.php and login.php. The login form is pretty simple (it's inside index.php):

<fieldset class="right">
    <label for="email">Email

        <input id="email" name="email" type="text" value=""/>
    </label>
    <label for="password">Password
        <input id="password" name="password" type="password" />
        <a href="#" onclick="$('#password-box').toggle();" >Forgot your password?<span></span></a>
    </label>
    <div class="btn-login"><button type="submit" value="Login"></button></div>
</fieldset>
</form>

的login.php 内容:

<?php
//  Include the launcher file.
require_once('globals.php');
require_once(CORE . 'launcher.php');

//  Collect the information sent to us.
$mail = (isset($_POST['email'])) ? $_POST['email'] : '';
$password = (isset($_POST['password'])) ? $_POST['password'] : '';

$LoginError = false;
    // AUTHORIZATION STUFF HERE
if ($LoginError) {
    header('Status: 200');
    header('X-Test: test');
    header('Location: index.php');
    exit();
}

正如你所看到的,我送含万一有登录过程中发生错误的形式脚本自定义标题,在的index.php ,我使用 headers_list(),但我要送的头不是present在列表中。

As you can see, I'm sending a custom header to the script containing the form in case there was an error during signing in. In the index.php, I'm using headers_list(), but the header I'm sending is not present in the list.

是什么原因造成的?我试着 php_valueoutput_buffering,0的.htaccess 文件,但没有成功。

What is causing that? I've tried with php_value "output_buffering" "0" in the .htaccess file, but no success.

更新 检查在铬后,正在接收标头由浏览器,但不提供在PHP

UPDATE After checking in Chrome, the header is being received by the browser, but is not available in PHP.

在此先感谢。

推荐答案

重定向是由它对应导航到给定的位置客户端发送到并处理:的index.php 。你不应该指望当它从服务器请求的index.php 的自定义头是由浏览器提供。

The redirect is sent to and processed by the client which responds by navigating to the given Location: index.php. You should not expect that the custom header is provided by the browser when it is requesting index.php from the server.

CLIENT                                    SERVER
 |------- POST login.php ------------------>|
 |                                          |
 |<- 200, Location: index.php, X-Test:test -| (this is where you send the header)
 |                                          |
 |------- GET index.php ------------------->| (no header from client to server)

这篇关于PHP重定向与自定义页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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