Re: adding http digest authentication to php5
| From: | Rui Hirokawa | Date: | Sun, 01 Feb 2004 14:36:47 +0000 |
| Subject: | Re: adding http digest authentication to php5 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7456@lists.php.net to get a copy of this message | ||
Can I attach a php script ?
<?php // a sample for digest authentication
$realm="php-users";
$uri = $_SERVER['REQUEST_URI'];
$nonce = time();
$username = "taro";
$password = "secret";
function auth_func() {
global $realm, $nonce;
header('HTTP/1.0 401 Unauthorized');
header("WWW-authenticate: Digest realm=\"$realm\" nonce=\"$nonce\"");
die('password or user name is invalid.');
}
if (empty($_SERVER['PHP_AUTH_USER'])) {
auth_func();
} else {
$username = $_SERVER['PHP_AUTH_USER'];
$response = $_SERVER['PHP_AUTH_PW'];
$nonce = $_SERVER['PHP_AUTH_NONCE'];// response based on RFC2617 $a1 = md5("$username:$realm:$password"); $a2 = md5("GET:$uri"); $response0 = md5("$a1:$nonce:$a2"); print "response1:$response<br />"; print "response0:$response0<br />"; print "nonce:$nonce</br>"; if ($response == $response0) {
print "authenticated.<br />";} else {
print "not authenticated.<br />";} } ?>