编写php应用程序实现摘要式身份验证

 通基本身份认证一样,也可以使用PHP网页处理HTTP请求报头字段来匹配摘要式身份验证信息。例如下边的代码使用header()函数要求客户端使用Digest验证,它在HTTP消息报头中增加了一个WWW-Authenticate字段:

header('WWW-Authenticate:Digest Realm="MyRealm",nonce="47alf7cf25ce7",algorithm=MD5,qop="auth"');


下边代码描述的是一个使用摘要式身份验证的网页(首先取消Apache验证配置)。

 

1,'nc'=>1,'cnonce'=>1,'qop'=>1,'username'=>1,'uri'=>1,'response'=>1); //使用正则表达式解析Authorization报头的内容 preg_match_all('@(/w+)=([/'"]?)([a-zA-Z0-9=.//_-]+)/2@',$digest_str,$result,PREG_SET_ORDER); //将结果填充$data数组,并返回 $data=array(); foreach($result as $m){ $data[$m[1]]=$m[3]; unset($needed_parts[$m[1]]); } return $needed_parts?false:$data; } ?>

你可能感兴趣的:(php)