通过PHP进行HTTP 认证:
session_start();
if (!isset($_SERVER[‘PHP_AUTH_USER’]) && $_SESSION[‘login_out’]==true) {
header(‘WWW-Authenticate: Basic realm=”My Realm”‘);
header(‘HTTP/1.0 401 Unauthorized’);
}
elseif ($_GET[‘login_out’]) {
$_SESSION[‘login’]=true;
}
else {
$user_name=$form->input_check_filter($_SERVER[‘PHP_AUTH_USER’]);
$password=$form->md5($_SERVER[‘PHP_AUTH_PW’]);
$user=$db->get_one(‘select user_id from’.table(‘user’).”where user_name=’$user_name’
and password=’$password'”);
if ($user[‘user_id’]) {
$_SERVER[‘PHP_AUTH_USER’]=$user_name;
$_SESSION[‘login’]=false;
showmsg(‘登陆成功’);
}
}