[PHP]
error_reporting(7);
$username1=$username;
$passwd1=$passwd;
setcookie("username1","$username",0,"/");
setcookie("passwd1","$passwd",0,"/");
function checkAdmin($showMsg = true)
{
global $qry, $web_user, $userid, $username, $usergroupid;
$result = $qry->query_first("select id from webuser where id='$userid' and groupid=1");
if (!$result && $showMsg)
{
echo highlight("
您暂时没有使用该功能的权限");
return $result;
}
}
function auth($msg)
{
global $sitedomain;
session_start();
Header("HTTP/1.0 401 Unauthorized");
Header("WWW-authenticate: basic realm=\"$sitedomain\"");
showError($msg);
die();
}
if (!isset($username1))
{
auth("您需要重新登录后才能使用管理功能");
}
else
{
$username = $username1;
$username = addslashes(htmlspecialchars($username));
$user = $qry->query_first("select id,password,groupid from webuser where name='$username' and password=password('$passwd1')");
if (!$user)
{
auth("登录失败!您需要登录成功后才能使用管理功能");
}
else
{
$userid = $user[id];
$usergroupid = $user[groupid];
}
}
[/PHP]
请大家帮忙看看,我个人感觉不太好,现在想改成COOKIE登陆,但不晓得怎么改好。