标签:00
// header(‘HTTP/1.1 401 Authorization Required‘); // header(‘WWW-Authenticate: Basic realm="PHP Secured"‘); //用户名和口令列表 $users = array( ‘aaa‘ => ‘aaa‘, ‘bbb‘ => ‘bbb‘ ); //检验是否有用户名 if(!isset($_SERVER[‘PHP_AUTH_USER‘])) { header(‘HTTP/1.1 401 Unauthorized‘); header(‘WWW-Authenticate: Basic realm="PHP Secured"‘); exit(‘This page requires authentication‘); } //检验是否有该用户 if(!isset($users[$_SERVER[‘PHP_AUTH_USER‘]])) { header(‘HTTP/1.1 401 Unauthorized‘); header(‘WWW-Authenticate: Basic realm="PHP Secured"‘); exit(‘Unauthorized!‘); } //检验口令是否正确 if($users[$_SERVER[‘PHP_AUTH_USER‘]] != $_SERVER[‘PHP_AUTH_PW‘]) { header(‘HTTP/1.1 401 Unauthorized‘); header(‘WWW-Authenticate: Basic realm="PHP Secured"‘); exit(‘Unauthorized!‘); } //验证通过 echo ‘Username:‘.$_SERVER[‘PHP_AUTH_USER‘].‘<br/>‘; echo ‘Password:‘.$_SERVER[‘PHP_AUTH_PW‘].‘<br/>‘;
标签:00
原文地址:http://12631475.blog.51cto.com/12621475/1918206