//header('HTTP/1.1401AuthorizationRequired');//header('WWW-Authenticate:Basicrealm="PHPSecured"');//用户名和口令列表$users=array('aaa'=>'aaa','bbb'=>'bbb');//检验是否有用户名if(!isset($_SERVER['PHP_AUTH_USER'])){header('HTTP/1.1401Unauthorized');header('WWW-Authenticate:Basicrealm="PHPSecured"');exit('Thispagerequiresauthentication');}//检验是否有该用户if(!isset($users[$_SERVER['PHP_AUTH_USER']])){header('HTTP/1.1401Unauthorized');header('WWW-Authenticate:Basicrealm="PHPSecured"');exit('Unauthorized!');}//检验口令是否正确if($users[$_SERVER['PHP_AUTH_USER']]!=$_SERVER['PHP_AUTH_PW']){header('HTTP/1.1401Unauthorized');header('WWW-Authenticate:Basicrealm="PHPSecured"');exit('Unauthorized!');}//验证通过echo'Username:'.$_SERVER['PHP_AUTH_USER'].'<br/>';echo'Password:'.$_SERVER['PHP_AUTH_PW'].'<br/>';