SecondGear
SecondGear

Reputation: 1113

http basic auth - PHP_AUTH_USER & PHP_AUTH_PW not being set

I've looked at several other questions on stackoverflow dealing with this issue HTTP Auth via PHP - PHP_AUTH_USER not set? and PHP_AUTH_USER not set? , but they all point at issues with "Server API" being set to CGI, for me it's set to "Apache 2.0 Handler".

I'm using UBUNTU 12.04LTS.

I have a simple script in my docroot called my.php:

<?php
echo "Username: " . $_SERVER["PHP_AUTH_USER"] . ", Password: " . $_SERVER["PHP_AUTH_PW"];
?

When I run wget, I can see that both are empty:

wget -v --http-user=johnsmith --http-password=mypassword http://192.168.1.163/my.php

returns:

Username: , Password: 

I have the following apache modules enabled:

/etc/apache2/mods-enabled
alias.conf       authn_file.load       authz_host.load  autoindex.load  deflate.load  env.load   negotiation.conf  php5.load        rewrite.load   status.conf
alias.load       authz_default.load    authz_user.load  cgi.load        dir.conf      mime.conf  negotiation.load  reqtimeout.conf  setenvif.conf  status.load
auth_basic.load  authz_groupfile.load  autoindex.conf   deflate.conf    dir.load      mime.load  php5.conf         reqtimeout.load  setenvif.load

I also tried adding a line to my .htaccess for "AuthType Basic" to no avail.

Is there something else that needs to be set or config'ed?

Upvotes: 2

Views: 3902

Answers (2)

Teddy
Teddy

Reputation: 1023

For PHP-CGI:

in .htaccess add this:

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

and at the beginning of your script add this:

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

Upvotes: 0

ahmadsc
ahmadsc

Reputation: 41

It appears to me that you're not sending the needed parameters properly!
Have you tried wget http://johnsmith:[email protected]/my.php?

Upvotes: 1

Related Questions