你现在的位置:首页 > PHP网站建设知识库 > phpcms > 正文

phpcms v9代码分析

一、数据库加载:
数据库配置文件:安装时填写的数据库配置数据存储在caches/configs/database.php

(1)index.php入库文件,并加载phpcms/base.php。
(2)index.php文件:pc_base::creat_app();
(3)phpcms/libs/classes/application.class.php:$controller = $this->load_controller();
默认加载:phpcms\modules\content\index.php
(4)phpcms\modules\content\index.php:$this->db = pc_base::load_model('content_model');
加载文件:phpcms/model/content_model.class.php
(5)phpcms/model/content_model.class.php:$this->db_config = pc_base::load_config('database');
(6)加载配置文件:caches/configs/database.php

二、模板解析:
文件:phpcms/libs/functions/global.func.php
调用:include template($module,$template);

模板缓存文件:phpcms/libs/classes/template_cache.class.php
template_compile:模板编译函数

三、用户登录模块(phpsso关联)
1、phpcms/modules/member/index.php
登陆操作:login()
...
$status = $this->client->ps_member_login($username, $password);//phpsso中判断用户登陆,正确返回用户数据array
...//如果本地用户信息不存在,则插入数据,保持数据一致。
...
$synloginstr = $this->client->ps_member_synlogin($r['phpssouid']);//phpsso用户同步登陆函数
//==========其余分析至[phpsso通信]==========

四、用户注册模块(phpsso关联)
1、phpcms/modules/member/index.php
注册操作:register()
$this->_session_start();//加载phpcms/libs/classes/session_mysql.class.php
...
$member_setting = getcache('member_setting');//加载用户配置
...
$siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1;//默认siteid为1
...
$this->_init_phpsso();//加载phpcms/modules/member/classes/client.class.php
//phpcms/base.php中load_app_class()函数的defined("ROUTE_M")来至于phpcms/libs/classes/application.class.php
...
$status = $this->client->ps_member_register($userinfo['username'], $userinfo['password'], $userinfo['email'], $userinfo['regip'], $userinfo['encrypt']);//phpsso中添加注册用户,返回phpssouid
...
$userid = $this->db->insert($userinfo, 1);//本地用户数据添加。密码加密存储

五、后台部分整理
1、口令卡(移除)
配置文件:caches/configs/system.php

后台登陆/退出:phpcms/modules/admin/index.php
后台管理:phpcms/modules/admin/admin_manage.php

口令卡类:phpcms/modules/admin/classes/card.class.php
管理员类:phpcms/modules/admin/classes/admin.class.php

语言文件:phpcms/languages/zh-cn/admin.lang.php
phpcms/languages/zh-cn/system_menu.lang.php

模板文件:phpcms/modules/admin/templates/admin_list.tpl.php
phpcms/modules/admin/templates/login_card.tpl.php
phpcms/modules/admin/templates/admin_card.tpl.php

2、后台登陆
phpcms/modules/admin/classes/admin.class.php
常规下加载phpcms/libs/classes/session_mysql.class.php
...session_start();//开启session

phpcms/modules/admin/classes/admin.class.php
状态判断:check_admin()

phpcms/modules/admin/index.php
登陆操作:login()
...
$_SESSION['userid'] = $r['userid'];
...
$cookie_time = SYS_TIME+86400*30;
...
param::set_cookie('userid', $r['userid'],$cookie_time);
...
//设置session和cookie