iis HTTP auth scripted in PHP4
| From: | Martin McWhorter | Date: | Sat, 28 Oct 2000 21:12:34 +0000 |
| Subject: | iis HTTP auth scripted in PHP4 | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-3570@lists.php.net to get a copy of this message | ||
Hello,
I am trying to script HTTP authentication in PHP4 using iis4 (pronounced
two-S-four) as the web server.
I have followed a couple of examples (mostly in php3) but have had no
success.
This is one that I have translated from php3 to four... but I still have
no luck. As well in my php.ini I turned global variables on (so that
$PHP_AUTH_USER and $PHP_AUTH_PW get passed back to the script) but still
I get no luck.
I get the Logon Validation prompt from the browser, but it never gets
past that.
Anyone have any success.
I am running php-4.0.2 in isapi mode (needed for http Auth done by php
-- the 4.0.3 bin would not work in isapi) in iis I have only anonymous
authentication enabled to allow PHP to authenticate..
Here is my code -- well that i stole from an example:
<?php
if ($PHP_AUTH_USER == "" && $PHP_AUTH_PW == "" &&
ereg("^Basic ",
$HTTP_SERVER_VARS["HTTP_AUTHORIZATION"])) {
list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(":",
base64_decode(substr($HTTP_AUTHORIZATION, 6)));
echo $PHP_AUTH_USER, $PHP_AUTH_PW;
}
$authenticated = 0;
if ($PHP_AUTH_USER != "" || $PHP_AUTH_PW != "") {
//put your authentication here (e.g. database lookup)
$authenticated = ($PHP_AUTH_USER == "test" && $PHP_AUTH_PW = "123");
}
// $authenticated = "true";
if(!$authenticated) {
header("WWW-Authenticate: Basic realm=\"Job Address Database\"");
if (ereg("Microsoft", $HTTP_SERVER_VARS["SERVER_SOFTWARE"]))
header("Status: 401 Unauthorized");
} else {
header("HTTP/1.0 401 Unauthorized");
echo "Access denied";
exit;
}