/www/wwwroot/blog.gumengya.com/usr/plugins/AMP/templates/MIPpage.php on line 31
">

php页面验证密码访问

2020-08-31T19:52:00

一个简单的验证

<?php
header("Content-type: text/html; charset=utf-8");
function code($user, $pass) {
      $users = ['admin'=>'123456'];
      if(isset($users[$user]) && $users[$user] === $pass) {
        return true;
      } else {
        return false;
      }
}
if(!code(@$_SERVER['PHP_AUTH_USER'], @$_SERVER['PHP_AUTH_PW'])) {
     http_response_code(401);
     header('WWW-Authenticate:Basic realm="My website"');
     echo '需要用户名和密码才能继续访问'; 
     exit;
} else {
    
}
echo "验证成功";
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »