note 68464 added to features.http-auth
| From: | blah at blah dot com | Date: | Thu, 27 Jul 2006 19:46:19 +0000 |
| Subject: | note 68464 added to features.http-auth | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115283@lists.php.net to get a copy of this message | ||
Getting PHP Authentication to work with CGI-bin.
You must have mod_rewrite installed for this to work. In the directory (of the file) you want to
protect, for the .htaccess file:
# PHP (CGI mode) HTTP Authorization with ModRewrite:
# most right example with header check for non empty:
RewriteEngine on
RewriteCond %{HTTP:Authorization} !^$
RewriteRule ^test.php$ test.php?login=%{HTTP:Authorization}
Change the Rewrite rule to whatever you want it to be. For simplicity, this example only applies to
one file, test.php and only if the HTTP Authorization needs to take place.
In the php file:
<?
if (isset($_GET['login'])) {
$d = base64_decode( substr($_GET['login'],6) );
list($name, $password) = explode(':', $d);
echo 'Name:' . $name . "<br>\n";
echo 'Password:' . $password . "<br>\n";
} else {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'You are not authorized. Bad user, bad!';
exit;
}
?>
You need to get rid of the first 6 characters for some reason, then decode the Auth data from its
base64 format. Then it's a simple matter of extracting the data. You can even pass the data to
the $_SERVER variables $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'].
These are the variables that get the login data if you have PHP running as an Apache module. This is
useful for mods or plugins.
----
Server IP: 64.71.164.2
Probable Submitter: 70.36.170.37
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/features.http-auth.php
Edit -- http://master.php.net/note/edit/68464
Del: integrated -- http://master.php.net/note/delete/68464/integrated
Del: useless -- http://master.php.net/note/delete/68464/useless
Del: bad code -- http://master.php.net/note/delete/68464/bad+code
Del: spam -- http://master.php.net/note/delete/68464/spam
Del: non-english -- http://master.php.net/note/delete/68464/non-english
Del: in docs -- http://master.php.net/note/delete/68464/in+docs
Del: other reasons-- http://master.php.net/note/delete/68464
Reject -- http://master.php.net/note/reject/68464
Search -- http://master.php.net/manage/user-notes.php