/SiteDev2/Digest認証
sd_class/basicAuth.phpを置き換えます。
$realmを好きに書き換えてください。
<?php
// basic 認証クラス
// copyright (C) phpspot
class basicAuth{
var $users = array();
var $realm = "A.K.I. Home";
function basicAuth($arg){
if(is_array($arg)){
$this->users = $arg;
}
}
function authHeader(){
header('WWW-Authenticate: Digest realm="'.$this->realm.'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($this->realm).'"');
header('HTTP/1.0 401 Unauthorized');
}
function execute(){
if(empty($_SERVER['PHP_AUTH_DIGEST'])){
$this->authHeader();
return FALSE;
}else{
if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||!isset($this->users[$data['username']])){
$this->authHeader();
return FALSE;
}
$A1 = md5($data['username'] . ':' . $this->realm . ':' . $this->users[$data['username']]);
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
if ($data['response'] != $valid_response){
$this->authHeader();
return FALSE;
}
return TRUE;
}
}
}
/*
example)
$a = new BasicAuth;
$flg = $a->execute();
if($flg == FALSE){ echo "cant";exit; }
*/
function http_digest_parse($txt)
{
$data = array();
$response = explode(",", str_replace('"', '', $txt));
foreach ($response as $v) {
preg_match('/^([^\=]*)\=(.*)$/',str_replace(' ','',$v),$tmp);
$dt[$tmp[1]] = $tmp[2];
}
return $dt;
}
?>