大概上说下后台管理员的登录过程,实现的动作是使用login.inc.php文件
if($dosubmit)
{
require PHPCMS_ROOT.'languages/'.LANG.'/member.lang.php';
require PHPCMS_ROOT.'member/include/member.class.php';
$member = new member();
if(!isset($forward)) $forward = URL;
if(!isset($checkcodestr)) $checkcodestr = '';
if($code->check()) checkcode($checkcodestr, 1, HTTP_REFERER);
$result = $member->login($username, $password);
member类的实现文件在member.class.php文件中
function login($username, $password, $cookietime = 0) { //............... if(!$cookietime) $get_cookietime = get_cookie('cookietime'); $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0); $cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth_key = md5(AUTH_KEY.$_SERVER['HTTP_USER_AGENT']); $phpcms_auth = phpcms_auth($this->_userid."\t".$md5_password, 'ENCODE', $phpcms_auth_key); set_cookie('auth', $phpcms_auth, $cookietime); set_cookie('cookietime', $_cookietime, $cookietime); //............... }
后台的登录的过程是使用用户名检索出加密后的密码,然后与前台输入过来的密码,加密并进行比较,如果相同,那就设置"auth",cookie到前台,cookie中包含用户名与密码,加密过的然后转向到"?",也就是当前admin文件,
在admin.php中包含的include/common.inc.php中
$phpcms_auth = get_cookie('auth'); if($phpcms_auth) { $auth_key = md5(AUTH_KEY.$_SERVER['HTTP_USER_AGENT']); list($_userid, $_password) = explode("\t", phpcms_auth($phpcms_auth, 'DECODE', $auth_key)); $_userid = intval($_userid); $sql_member = "SELECT * FROM `".DB_PRE."member_cache` WHERE `userid`=$_userid"; $r = $db->get_one($sql_member); if(!$r && cache_member()) { $r = $db->get_one($sql_member); } if($r && $r['password'] === $_password) { if($r['groupid'] == 2) { set_cookie('auth', ''); showmessage($LANG['userid_banned_by_administrator']); } @extract($r, EXTR_PREFIX_ALL, ''); } else { $_userid = 0; $_username = ''; $_groupid = 3; set_cookie('auth', ''); } unset($r, $phpcms_auth, $phpcms_auth_key, $_password, $sql_member); }
首页判断cookie("auth")是否有值,如果有值,先解密,找出userid,并在数据库上检索出password与当前的password是否相同,如果相同就通过,如果不同那就清除cookie,转向到登录界面