• 问答项目---用户注册的那些事儿(PHP验证)


    JS 验证之后,还需要通过PHP验证:

    提交过来的名称不一样,可以用字段映射:

    在自动验证的时候,如果这个字段被映射,那么自动验证的时候,自动验证的就是 映射过后的字段;

    控制器示例

    //注册表单处理
    Public function register () {
        if (!$this->isPost()) halt('页面不存在');
    
        $db = D('User');
        if (!$db->create()) {
            $this->error($db->getError());
        }
        $username = $db->username;
        if (!$uid = $db->add()) $this->error('注册失败,请重试...');
    
        session('uid', $uid);
        session('username', $username);
        $this->success('注册成功,正在为您跳转...', __APP__);
    }

    自动验证模型示例

    <?php
    /**
     * 用户表操作模型
     */
    Class UserModel extends Model {
    
        //字段映射
        Protected $_map = array(
            'pwd' => 'password'
        );
    
        //自动验证
        Protected $_validate = array(
            array('account', 'require', '帐号不能为空'),
            array('account', '/^[a-zA-Z]w{6,19}$/s', '帐号格式不正确', 1, 'regex'),
            array('account', '', '帐号已存在', 1, 'unique'),
            array('username', 'require', '用户名不能为空'),
            array('username', '/^[x80-xffw]{2,14}$/s', '用户名格式不正确', 1, 'regex'),
            array('username', '', '用户名已存在', 1, 'unique'),
            array('password', 'require', '密码不能空'),
            array('password', '/^w{6,20}$/s', '密码格式不正确'),
            array('pwded', 'password', '两次密码不一致', 1, 'confirm')
            );
    
        //自动完成
        Protected $_auto = array(
            array('password', 'md5', 1, 'function'),
            array('logintime', 'time', 1, 'function'),
            array('loginip', 'get_client_ip', 1, 'function'),
            array('registime', 'time', 1, 'function')
            );
    }
    ?>

     

  • 相关阅读:
    创建窗口
    文件映射
    匿名管道
    MFC之进度条CProgressCtrl
    跨进程使用句柄和文件操作
    redis安装配置
    git全部操作
    idea中Entity实体中报错:cannot resolve column/table/
    Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezon
    sql操作
  • 原文地址:https://www.cnblogs.com/e0yu/p/7446030.html
Copyright © 2020-2023  润新知