PHP首部认证
// User name and password for authentication$username = 'rock';
$password = 'roll';
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
// The user name/password are incorrect so send the authentication headers
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Guitar Wars"');
exit('Guitar Wars
Sorry, you must enter a valid user name and password to access this page.');
}
?>
登录后复制
以上就介绍了PHP首部认证,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。