index.php中indexControl 继承了SystemControl类。
父类SystemControl属性protected $admin_info;在父类_construct()中对该属性进行了赋值,并传递给了子类indexControl,供子类使用。
父类_construc()中对管理员信息赋值的相应操作:
$this->admin_info = $this->systemLogin();
if ($this->admin_info['id'] != 1){
// 验证权限
$this->checkPermission();
}
--------------------------------------------------------------------------------------------------------------------------------------
1、其中SystemLogin()为后台登录验证,返回管理员信息:
protected final function systemLogin(){
//取得cookie内容,解密,和系统匹配
$user = unserialize(decrypt(cookie('sys_key'),MD5_KEY)); //未细看decrypt()是解密函数 cookie()从全局变量$_COOKIE中获取
//cookie('sys_key')是一串字符串
//decrypt(cookie('sys_key'),MD5_key)得到字符串:
a:4:{s:4:"name";s:5:"admin";s:2:"id";s:1:"1";s:3:"gid";s:1:"0";s:2:"sp";s:1:"1";}
//$user为数组:
array (size=4)
'name' =>
string
'admin' (length=5)
'id' =>
string
'1' (length=1)
'gid' =>
string
'0' (length=1)
'sp' => '1' (length=1)
//serialize()和unserialize():http://www.cnblogs.com/yeer/archive/2009/03/25/1421161.html
if (!key_exists('gid',(array)$user) || !isset($user['sp']) || (empty($user['name']) || empty($user['id']))){
@header('Location: index.php?act=login&op=login');exit; //将信息发送回浏览器,并让浏览请求Location中的URL,浏览器地址栏显示Location中URL
}else {
$this->systemSetKey($user);//调用本类方法
}
return $user;
}
protected final function systemSetKey($user){
setNcCookie('sys_key',encrypt(serialize($user),MD5_KEY),3600,'',null); //setNcCookie()、encrypt()加密函数公共方法写在core.php中
}
function setNcCookie($name, $value, $expire='3600', $path='', $domain='', $secure=false){
if (empty($path)) $path = '/';
if (empty($domain)) $domain = SUBDOMAIN_SUFFIX ? SUBDOMAIN_SUFFIX : '';
$name = defined('COOKIE_PRE') ? COOKIE_PRE.$name : strtoupper(substr(md5(MD5_KEY),0,4)).'_'.$name;
$expire = intval($expire)?intval($expire):(intval(SESSION_EXPIRE)?intval(SESSION_EXPIRE):3600); //intval已封装
$result = setcookie($name, $value, time()+$expire, $path, $domain, $secure); //setcookie()向客户端发送一个HTTP cookie
$_COOKIE[$name] = $value;
}
------------------------------------------------------------------------------------------------------------------------------------------
2.checkPermission()权限验证 通过验证来确定返回的菜单信息