从传入的 PHP 请求中获取自定义授权标头 [英] Fetching custom Authorization header from incoming PHP request

查看:31
本文介绍了从传入的 PHP 请求中获取自定义授权标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在 PHP 中解析一个传入请求,它具有以下标头集:

So I'm trying to parse an incoming request in PHP which has the following header set:

Authorization: Custom Username

一个简单的问题:我到底是怎么得到它的?如果是 Authorization: Basic,我可以从 $_SERVER["PHP_AUTH_USER"] 获取用户名.如果是 X-Custom-Authorization: Username,我可以从 $_SERVER["HTTP_X_CUSTOM_AUTHORIZATION"] 获取用户名.但是这些都不是由自定义授权设置的,var_dump($_SERVER) 显示没有提到标题(特别是,AUTH_TYPE 丢失),PHP5 函数如 get_headers() 仅适用于对传出请求的响应.我正在 Apache 上运行 PHP 5,并安装了开箱即用的 Ubuntu.

Simple question: how on earth do I get my hands on it? If it was Authorization: Basic, I could get the username from $_SERVER["PHP_AUTH_USER"]. If it was X-Custom-Authorization: Username, I could get the username from $_SERVER["HTTP_X_CUSTOM_AUTHORIZATION"]. But neither of these are set by a custom Authorization, var_dump($_SERVER) reveals no mention of the header (in particular, AUTH_TYPE is missing), and PHP5 functions like get_headers() only work on responses to outgoing requests. I'm running PHP 5 on Apache with an out-of-the box Ubuntu install.

推荐答案

如果您只打算使用 Apache,您可能需要查看 apache_request_headers().

If you're only going to use Apache you might want to have a look at apache_request_headers().

这篇关于从传入的 PHP 请求中获取自定义授权标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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