PHP var_dump()上的授权标头为空

时间:2022-06-25 00:06:55

I'm sending a header to server with the following request headers:

我正在使用以下请求标头向服务器发送标头:

Host: xx.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: xx.com
Authorization: Bearer mytoken1234
X-Requested-With: XMLHttpRequest
Connection: keep-alive

On my php file I'm trying to view the headers with var_dump() and it shows following:

在我的php文件中,我正在尝试使用var_dump()查看标头,它显示如下:

["HTTP_ACCEPT"]=>
  string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
 ["HTTP_ACCEPT_ENCODING"]=>
  string(13) "gzip, deflate"
  ["HTTP_ACCEPT_LANGUAGE"]=>
  string(23) "en-US,en;q=0.8,fi;q=0.6"
  ["HTTP_AUTHORIZATION"]=>
  string(0) ""
  ["HTTP_CACHE_CONTROL"]=>
  string(9) "max-age=0"
  ["HTTP_CONNECTION"]=>
  string(10) "keep-alive"
  ["HTTP_COOKIE"]=>
  string(71) "cpsession=scocta5%3aBcbKZGvPoUCv2Yhb%2c2dc8a5c3bd6713b6ab029f16a46980e7"

I tried adding following lines to my .htaccess:

我尝试在我的.htaccess中添加以下行:

   SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

or

   RewriteEngine On
   RewriteCond %{HTTP:Authorization} ^(.*)
   RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

Without these settings, Authorization header was not showing on var_dump() at all but now it's just string(0) "". Why isn't my server getting the Authorization header content?

没有这些设置,授权标头根本没有显示在var_dump()上,但现在它只是字符串(0)“”。为什么我的服务器没有获得Authorization标头内容?

1 个解决方案

#1


0  

You can use apache_request_headers function:

您可以使用apache_request_headers函数:

$headers = apache_request_headers();
var_dump($headers['Authorization']);

#1


0  

You can use apache_request_headers function:

您可以使用apache_request_headers函数:

$headers = apache_request_headers();
var_dump($headers['Authorization']);