nabiscooreo
New Member
- Messages
- 1
- Reaction score
- 0
- Points
- 0
Hi~I want to use http authorization,so i put the following in .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
and the index.php is as follow:
<?php
if (!isset($_SERVER['HTTP_AUTHORIZATION'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
// split the user/pass parts
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
echo "<p>Hello, </p>".$_SERVER['PHP_AUTH_USER'];
echo "<p>You entered as your password: ".$_SERVER['PHP_AUTH_PW']."</p>";
}
?>
When i visited the index.php,after input the username and password in login window, the login windows appeared again. Seems that the "$_SERVER['HTTP_AUTHORIZATION']" was always unset.What could I do?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
and the index.php is as follow:
<?php
if (!isset($_SERVER['HTTP_AUTHORIZATION'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
// split the user/pass parts
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
echo "<p>Hello, </p>".$_SERVER['PHP_AUTH_USER'];
echo "<p>You entered as your password: ".$_SERVER['PHP_AUTH_PW']."</p>";
}
?>
When i visited the index.php,after input the username and password in login window, the login windows appeared again. Seems that the "$_SERVER['HTTP_AUTHORIZATION']" was always unset.What could I do?