新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
// 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'].'
'; echo 'Password:'.$_SERVER['PHP_AUTH_PW'].'
';