1

I had this question posted here, maybe admins did not understand it correctly and marked it as duplicate, so I am posting it again, because I cannot access these variables as defined here. And so called duplicate question does not help me with my query. In my case when I call PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE they are empty, null. Can someone please help me understand why? My .htaccess file:

AuthType Basic

AuthName "You need to login to access this page."
AuthUserFile /usr/local/..../.htpasswd
Require valid-user

RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

When I do var_dump($_SERVER); in my PHP code, I see that none of these variables are set, why is that? Is it impossible to access these variables if basic HTTP Authentication used with .htaccess and .htpasswd files alone?

3
  • Is $_SERVER['HTTP_AUTHORIZATION'] or $_SERVER['REWRITE_HTTP_AUTHORIZATION'] set? Commented Jun 26, 2018 at 8:29
  • @Evert Hi, thank you for looking at my problem. No these variables are net set either. Commented Jun 26, 2018 at 8:37
  • I think its because my server is set with CGI. I found some workarounds for this, but they don't work either... Commented Jun 26, 2018 at 10:21

1 Answer 1

0

The answer is: PHP doesn't get AUTH-variables because Apache doesn't send them to PHP-interpreter. Why?

This part will work for PHP-CGI:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

Only if

Apache won't pass it to CGI apps unless you compile it with the SECURITY_HOLE_PASS_AUTHORIZATION flag. How can I use Basic HTTP Authentication in PHP?

You should disable basic auth in .htaccess file and use it in PHP. Manual: http://php.net/manual/en/features.http-auth.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.