note 52405 added to features.http-auth
| From: | charlyattowebsdotcom at osu1 dot php dot net | Date: | Fri, 29 Apr 2005 17:13:45 +0000 |
| Subject: | note 52405 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88761@lists.php.net to get a copy of this message | ||
A simpler approach on the post of:
bernard dot paques at bigfoot dot com
24-Sep-2004 01:42
This is another "patch" to the PHP_AUTH_USER and PHP_AUTH_PW server variables problem
running PHP as a CGI.
First of all don't forget this fragment of code in your .htaccess (it's the only thing you
need to make it work with mod_rewrite):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
</IfModule>
Then login.php
<?php
$a = base64_decode( substr($_SERVER["REMOTE_USER"],6)) ;
if ( (strlen($a) == 0) || ( strcasecmp($a, ":" ) == 0 ))
{
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
}
else
{
list($name, $password) = explode(':', $a);
$_SERVER['PHP_AUTH_USER'] = $name;
$_SERVER['PHP_AUTH_PW'] = $password;
}
echo 'PHP_AUTH_USER =' . $_SERVER['PHP_AUTH_USER'] . '<br>';
echo 'PHP_AUTH_PW =' . $_SERVER['PHP_AUTH_PW'] . '<br>';
echo 'REMOTE_USER =' . $_SERVER['REMOTE_USER'] . '<br>';
?>
First, we decode the base64 encoded string discarding the first 6 characters of "Basic "
and then we do a regular validation.
At the end of the script we print the variables to verify it's working. This should be ommited
in the production version.
It's a variation of the script by Bernard Paques.
Thanks to him for that snippet.
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52405
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52405&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52405&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52405&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52405&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52405&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52405&report=yes
Search -- http://master.php.net/manage/user-notes.php