$_SERVER['HTTP_AUTHORIZATION'] is missing

落花浮王杯 提交于 2021-01-03 06:53:06

问题


This is my .htaccess file:

RewriteEngine on

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Even though I have added below line to my .htaccess file I cannot access $_SERVER['HTTP_AUTHORIZATION'].

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

When I'm doing print_r($_SERVER) I can't find HTTP_AUTHORIZATION. I have googled for an answer but none of them worked.


回答1:


If you're using rewrite rules to pass this header - it may be prefixed by REDIRECT_ Try $_SERVER['REDIRECT_HTTP_AUTHORIZATION'].

But since 2.0.13 Yii has an abstraction for this, I suggest to use it:

  • Request::getAuthUser() to get user.
  • Request::getAuthPassword() to get password.
  • Request::getAuthCredentials() to get both.



回答2:


I have previously faced same issue and I solved by adding this line at the top of my .htaccess that is at the root directory

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0


来源:https://stackoverflow.com/questions/51806446/serverhttp-authorization-is-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!