http认证 PHP中的基本HTTP认证
PHP中的基本HTTP认证 [代码片段(18行)]
<?php if (!isset($_SERVER['PHP_AUTH_USER'])) { header("WWW-Authenticate: Basic realm=\"My Private Area\""); header("HTTP/1.0 401 Unauthorized"); print "You need valid credentials to get access!\n"; exit; } else { if (($_SERVER['PHP_AUTH_USER'] == 'mani') && ($_SERVER['PHP_AUTH_PW'] == 'w#m3nt0r')) { print "Welcome to the private area!"; } else { header("WWW-Authenticate: Basic realm=\"My Private Area\""); header("HTTP/1.0 401 Unauthorized"); print "You need valid credentials to get access!\n"; exit; } } ?>
精彩图集
精彩文章