php,httpbasic验证

function authenticate() { header('WWW-Authenticate: Basic realm=""'); header('HTTP/1.0 401 Unauthorized'); echo "You must enter a valid login ID and password to access this resource/n"; exit; } if (addslashes($_SERVER['PHP_AUTH_USER'])!= 'huangshuai' || addslashes($_SERVER['PHP_AUTH_PW'])!= 'adminadmin') { header('WWW-Authenticate: Basic realm=""'); header('HTTP/1.0 401 Unauthorized'); echo "对不起,无权进入! user=".$_SERVER['PHP_AUTH_USER']."password=".$_SERVER['PHP_AUTH_PW']; //后面这半句我是为了测试而加上去的; } else { echo "进入! user=".$_SERVER['PHP_AUTH_USER']."password=".$_SERVER['PHP_AUTH_PW']; //后面这半句我是为了测试而加上去的; echo "

Welcome: {$_SERVER['PHP_AUTH_USER']}
"; echo date('h:i:s') . "
"; //暂停 10 秒 //sleep(10); //重新开始 //echo date('h:i:s'); //header('WWW-Authenticate: Basic realm=""'); //header('HTTP/1.0 401 Unauthorized'); } 

 

你可能感兴趣的:(php)