php 模拟 http验证
<?php if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo '需要验证用户名、密码!'; exit; } else if($_SERVER['PHP_AUTH_USER']=="admin" && $_SERVER['PHP_AUTH_PW']=="admin"){ echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>"; echo "<p>登陆成功!You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>"; } else { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo ' 用户名、密码有误!'; exit; } ?>