简体   繁体   中英

PHP Apache Authorization Header

I'm having trouble retrieving the Authorization Header sent by Angular to Wamp Apache PHP.

Here is a snapshot of my chrome dev tools:

在此处输入图像描述

After a lot of research I was able to get the $_SERVER["HTTP_AUTHORIZATION"] variable to appear in PHP by adding any of those to the .htaccess file:

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

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

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]

The following variations didn't work for me (PS: they may be viable for other people):

CGIPassAuth On

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

My issue is that the Header is now present in PHP but EMPTY .

在此处输入图像描述

An example of API endpoint being use

在此处输入图像描述 Here is my setup:

  • PHP 7.2.1
  • APACHE 2.4.35
  • WAMP 3.1.4

I think you should try $_SERVER['Authorization']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM