wc之初认识

1.wc的运行流程:

①配置虚拟主机 

在httpd-vhosts.conf配置wc.com---对应目录为---->E:\wamp\www\WeCenter2.0\UPLOAD

在hosts里配置 127.0.0.1 wc.com

在浏览器中输入wc.com,应用会先找到E:\wamp\www\WeCenter2.0\UPLOAD\index.php

②在index.php会检查   //检查有没有安装过。如果没有安装过就跳转到install.php页面进行安装

//检查有没有安装过。如果没有安装过就安装
if (! file_exists(dirname(__FILE__) . '/system/config/database.php') AND ! file_exists(dirname(__FILE__) . '/system/config/install.lock.php'))
{
    header('Location: ./install/');
    exit;
}

如果安装过就:

include('system/system.php');

AWS_APP::run();

先看system/system.php文件.进来首先会定义ASW_PATH的路径,我电脑上的路径为:E:\wamp\www\WeCenter2.0\UPLOAD\system/

if (! defined('AWS_PATH'))
{
    define('AWS_PATH', dirname(__FILE__) . '/');
}

接下来又require_once一些初始化php文件:

require_once (AWS_PATH . 'init.php');

require_once (AWS_PATH . 'aws_app.inc.php');
require_once (AWS_PATH . 'aws_controller.inc.php');
require_once (AWS_PATH . 'aws_model.inc.php');

④先看require_once的第一个php文件--->init.php

首先上来进行了一些环境的判断,例如php版本之类的。不过我感觉兴趣的是下面三个路径

define('AWS_PATH', dirname(__FILE__) . '/');
define('ROOT_PATH', dirname(dirname(__FILE__)) . '/');
define('TEMP_PATH', dirname(dirname(__FILE__)) . '/tmp/');

AWS_PATH----------->E:\wamp\www\WeCenter2.0\UPLOAD\system/

ROOT_PATH---------->E:\wamp\www\WeCenter2.0\UPLOAD/

TEMP_PATH----------->E:\wamp\www\WeCenter2.0\UPLOAD/tmp/

接下来是一段这样的代码

if (function_exists('get_magic_quotes_gpc'))
{
    if (@get_magic_quotes_gpc()) // GPC 进行反向处理
    {
        if (! function_exists('stripslashes_gpc'))
        {
            function stripslashes_gpc(&$value)
            {
                $value = stripslashes($value);
            }
        }
        
        array_walk_recursive($_GET, 'stripslashes_gpc');
        array_walk_recursive($_POST, 'stripslashes_gpc');
        array_walk_recursive($_COOKIE, 'stripslashes_gpc');
        array_walk_recursive($_REQUEST, 'stripslashes_gpc');    
    }
}

判断是否存在方法get_magic_quotes_gpc,在php中这个方法的作用是:

取得 PHP 环境配置的变量 magic_quotes_gpc (GPC, Get/Post/Cookie) 值。返回 0 表示关闭本功能;返回 1 表示本功能打开;

注:magic_quotes_gpc 打开时,所有的 ‘ (单引号), ” (双引号), \ (反斜线) and 空字符会自动加上转义符\;

默认情况下,PHP 指令 magic_quotes_gpc 为 on,它主要是对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes();

不要对已经被 magic_quotes_gpc转义过的字符串使用 addslashes(),因为这样会导致双层转义;

遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测.

其实这个函数就是判断有PHP有没有自动调用addslashes 这个函数.

参考 -->这个博客

stripslashes-->返回一个去除转义反斜线后的字符串(\' 转换为 ' 等等)。双反斜线(\\)被转换为单个反斜线(\)。

注:addslashes()与stripslashes用法相反

array_walk_recursive -->对数组中的每个成员递归地应用用户函数

最后的代码还是引入一些配置文件

if (@ini_get('register_globals'))
{//echo 'register_globals = ' . ini_get('register_globals') . "\n";exit();
    if ($_REQUEST)
    {
        foreach ($_REQUEST AS $name => $value)
        {
            unset($$name);
        }
    }
    
    if ($_COOKIE)
    {
        foreach ($_COOKIE AS $name => $value)
        {
            unset($$name);
        }
    }
}

require_once(ROOT_PATH . 'version.php');
require_once(AWS_PATH . 'functions.inc.php');

if (file_exists(AWS_PATH . 'gz_config.inc.php'))
{
    rename(AWS_PATH . 'gz_config.inc.php', AWS_PATH . 'config.inc.php');
}

if (file_exists(AWS_PATH . 'config.inc.php'))
{
    require_once(AWS_PATH . 'config.inc.php');
}

load_class('core_autoload');

date_default_timezone_set('Etc/GMT-8');

⑤再看system.php中require_once另三个文件,从名字大概可以看出,aws_app.inc.php初始化app,aws_controller.inc.php初始化controller,

aws_model.inc.php初始化model

⑥看aws_controller.inc.php这个类做了些什么初始化的动作

public function __construct()
    {
        $this->user_id = USER::get_client_uid();//找见用户id

        $this->user_info = $this->model('account')->get_user_info_by_uid($this->user_id, TRUE);//通过id找到用户信息
        if ($this->user_id)
        {//又通过用户信息来找见用户所属哪个用户组
            $user_group = $this->model('account')->get_user_group($this->user_info['group_id'], $this->user_info['reputation_group']);
            if ($this->user_info['default_timezone'])
            {
                date_default_timezone_set($this->user_info['default_timezone']);
            }
        }
        else
        {//默认为游客-99即为游客
            $user_group = $this->model('account')->get_group_by_id(99);
        }
     //把用户组里的权限 赋值给 user_info
        $this->user_info['group_name'] = $user_group['group_name'];
        $this->user_info['permission'] = $user_group['permission'];

        AWS_APP::session()->permission = $this->user_info['permission'];

        if ($this->user_info['forbidden'] == 1)
        {//用户不允许登陆
            $this->model('account')->logout();

            H::redirect_msg(AWS_APP::lang()->_t('抱歉, 你的账号已经被禁止登录'), '/');
        }
        else
        {//用户允许登陆,并给前台页面赋值用户基本信息
            TPL::assign('user_id', (int)$this->user_id);
            TPL::assign('user_info', $this->user_info);
        }
     //这块应该是给用记初始化权限,待研究。
        if ($this->user_id and ! $this->user_info['permission']['human_valid'])
        {
            unset(AWS_APP::session()->human_valid);
        }
        else if ($this->user_info['permission']['human_valid'] and ! is_array(AWS_APP::session()->human_valid))
        {
            AWS_APP::session()->human_valid = array();
        }

        TPL::import_css(array(
            'css/global.css',
            'js/plug_module/style.css', 
        ));

        if (defined('SYSTEM_LANG'))
        {
            TPL::import_js(get_setting('base_url') . '/language/' . SYSTEM_LANG . '.js');
        }

        TPL::import_js(array(
            'js/jquery.js',
            'js/jquery.form.js',
            'js/plug_module/plug-in_module.js',
            'js/common.js',
            'js/global.js',
            'js/functions.js',
            'js/app.js',
        ));//通过get_setting方法在数据库表aws_system_setting找到site_name与base_url的信息
        $this->crumb(get_setting('site_name'), get_setting('base_url'));

        if ($plugins = AWS_APP::plugins()->parse($_GET['app'], $_GET['c'], 'setup'))
        {
            foreach ($plugins as $plugin_file)
            {
                include ($plugin_file);
            }
        }
        if (get_setting('site_close') == 'Y' AND $this->user_info['group_id'] != 1 AND !in_array($_GET['app'], array('account', 'upgrade')))
        {
            $this->model('account')->logout();

            H::redirect_msg(get_setting('close_notice'), '/account/login/');
        }//留给子类实现的方法
        $this->setup();
    }
//这个Controller大概就是做这些事情了

aws_model.inc.php这个类是model的父类,提供了一些增删改查的方法。作者注释很清楚,可以自己查看源码~~

⑧下面准备活动完,按照国际惯例应该写一个 "Hello world!"来表示咱们的征服欲了!Hello World 案例请看下一篇博客!

⑨完

我要青春像陈孝正一样,不能有一毫米的误差! 我要青春像合伙人一样,为了自尊而战!
原文地址:https://www.cnblogs.com/fanglove/p/3113432.html