$_SERVER 实现页面验证

通过超级变量达到页面登录验证

$authorization = false;
$user = $_SERVER['PHP_AUTH_USER'];
$users = [ 'admin123' => 'admin'];
if(in_array($user, $users) && $_SERVER['PHP_AUTH_PW'] == array_search($user, $users)){
    $authorization = true;
}
if(!$authorization){
    header("WWW-Authenticate:Basic realm='Private'");
    header('HTTP/1.0 401 Unauthorized');
    print "You are unauthorized to enter this area.";
}

 

posted @ 2018-11-30 19:26  进阶丶xiao路  阅读(285)  评论(0编辑  收藏  举报