Heim  >  Artikel  >  php教程  >  分析ECMall的注册与登录机制

分析ECMall的注册与登录机制

WBOY
WBOYOriginal
2016-06-13 09:39:071079Durchsuche

ecmall的注册流程index.php?app=member&act=register。

首先app是member,act是register方法。

index.php中。通过ecmall的startup方法来启动,主要包含了eccore/ecmall.php,startup方法中包含eccore/controller/app.base.php和eccore/model/model.base.php基础类,通过

$app = isset($_REQUEST['app']) ? trim($_REQUEST['app']) : $default_app;
$act = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : $default_act; 

来获取app和act。

如果是注册,act=member那么

$app_class_name = ucfirst($app) . 'App';
/* 实例化控制器 */
$app = new $app_class_name();

这里的$app = new MemberApp,调用MemberApp类里面的register方法。而在register方法里面,获取注册信息。通过global.lib.php中的ms方法。

include(ROOT_PATH . '/includes/passport.base.php');
include(ROOT_PATH . '/includes/passports/' . MEMBER_TYPE . '.passport.php'.regissword.php

而在register中ms()函数中以下程序

include(ROOT_PATH . '/includes/passports/' . MEMBER_TYPE . '.passport.php');
$class_name  = ucfirst(MEMBER_TYPE) . 'Passport';
$ms = new $class_name();

包含了default.passport.php中的DefaultPassport类,而他又继承了BasePassport,他有几行代码

$user_class_name = ucfirst($this->_name) . 'PassportUser';
$this->user = new $user_class_name();

所以程序里面的$this -> user就是这么来的。

$user_class_name其实就是includes/passports/default.passport.php中的DefaultPassportUser类。而他又extends了BasePassportUser,他调用了BasePassportUser中的_local_add()方法。而_local_add()方法通过调用model中的 member.model.php中的初始化数据,通过eccore/model/model.base.php中的BaseModel类下的function add($data, $compatible = false)方法来进行数据库处理。从而完成了注册功能。

    /**
     *  添加一条记录
     *
     *  @author Garbin
     *  @param  array $data
     *  @return mixed
     */
    function add($data, $compatible = false)
    {
        if (empty($data) || !$this->dataEnough($data))
        {
            return false;
        }
        $data = $this->_valid($data);
        if (!$data)
        {
            $this->_error('no_valid_data');
            return false;
        }
        $insert_info = $this->_getInsertInfo($data);
        $mode = $compatible ? 'REPLACE' : 'INSERT';
        $this->db->query("{$mode} INTO {$this->table}{$insert_info['fields']} VALUES{$insert_info['values']}");
        $insert_id = $this->db->insert_id();
        if ($insert_id)
        {
            if ($insert_info['length'] > 1)
            {
                for ($i = $insert_id; $i < $insert_id + $insert_info['length']; $i++)
                {
                    $id[] = $i;
                }
            }
            else
            {
                /* 添加单条记录 */
                $id = $insert_id;
            }
        }
        return $id;
    }

登录机制

ecmall电子商务系统的登陆,过程其实非常复杂。首先他是通过调用mall\default\login.html来调用登陆页面,调用的程序是通过app\frontend.base.php的login方法来调用来实现的。

if (!IS_POST)程序表示登陆页面的显示,通过$this->display('login.html')的调用来处理。ecmall的login.html页面主要有以下几个变量要传递,user_name,password,captcha三个变量,来用用于登陆验证。$user_name = trim($_POST['user_name'])和$password = $_POST['password']主要是用来接受用户名和密码的。通过连接登陆中心$ms =& ms()来调用$ms->user->auth($user_name, $password)来进行登陆验证的。

文件includes/global.lib.php中的function &ms()就是用来连接登陆中心的。 include(ROOT_PATH . '/includes/passports/' . MEMBER_TYPE . '.passport.php'); $class_name = ucfirst(MEMBER_TYPE) . 'Passport';$ms = new $class_name();这里就是来声明登陆对象的。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn