一个简单的验证
<?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 "验证成功";