问题描述
所以我试图在PHP中解析传入的请求,其中包含以下标头:
So I'm trying to parse an incoming request in PHP which has the following header set:
Authorization: Custom Username
简单的问题:我该如何得到它?如果它是授权:基本
,我可以从 $ _ SERVER [PHP_AUTH_USER]
获取用户名。如果它是 X-Custom-Authorization:用户名
,我可以从 $ _ SERVER [HTTP_X_CUSTOM_AUTHORIZATION]
获取用户名。但这些都不是由自定义授权设置的, var_dump($ _ SERVER)
显示没有提到标题(特别是 AUTH_TYPE
缺失),PHP5函数如 get_headers()
仅适用于对传出请求的响应。我在Apache上使用开箱即用的Ubuntu安装运行PHP 5.
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,您可能需要查看。
If you're only going to use Apache you might want to have a look at apache_request_headers()
.
这篇关于从传入的PHP请求中获取自定义Authorization标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!