Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_SERVER['HTTP_AUTHORIZATION'] is missing

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.

like image 407
Sanoj Silva Avatar asked Jan 03 '23 00:01

Sanoj Silva


2 Answers

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
like image 149
Stefano Mtangoo Avatar answered Jan 05 '23 04:01

Stefano Mtangoo


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.
like image 42
rob006 Avatar answered Jan 05 '23 04:01

rob006