M("Sessions")-add($data) 方法失效

浏览:1174 发布日期:2013/08/15 分类:求助交流 关键字: M()->add()
http://lj.soshow.org/home/index.php?a=index&m=Login&g=User
用户名 :adminaa 密码: 123456// 登录检测
    public function _check_login() {
        if($this->isPost()){
            if(empty($_POST['username'])) {
                $this->error('用户帐号必须!');
            }elseif (empty($_POST['password'])){
                $this->error('密码必须!');
            }
            if (empty($_POST['verify'])){
                $this->error('验证码必须!');
            }
            if($_SESSION['verify'] != md5($_POST['verify'])) {
                $this->error('验证码错误!');
            }
            if (!empty($_POST['loginreg'])){
                cookie('username',$_POST['username'],array('prefix'=>''));
                cookie('password',$_POST['password'],array('prefix'=>''));
            }else{
                cookie('username',null,array('prefix'=>''));
                cookie('password',null,array('prefix'=>''));
            }
            $map  =  array();
            $map_username = trim($_POST['username']);
            $map["status"]    =    array('eq',1);
            $map['_string'] = ' (username ="'.$map_username.'")  OR ( email = "'.$map_username.'")';
            $User    =   M("User");
            $auth = $User->where($map)->find();
            if(false == $auth) {
                $this->assign("jumpUrl",U('User/Login/index'));
                $this->error('帐号不存在或已禁用!');
            }else {
                if($auth['password'] != md5(md5($_POST['password']).C('USER_PW_KEY'))) {
                    $this->assign("jumpUrl",U('User/Login/index'));
                    $this->error('密码错误!');
                }
                $skey = md5(random(6).$auth['username']);
                //dump(urlencode(authcode($skey."\t".$auth['password']."\t".$auth['uid']."\t".$auth['username'], 'CODE')));
                //die("dd");
                cookie('auth', urlencode(authcode($skey."\t".$auth['password']."\t".$auth['uid']."\t".$auth['username'], 'CODE')));
//                dump(cookie('auth'));
    //            die("get cookie");
                $data = array();
                $auth['skey']    =    $skey;
                $data['uid']    =    $auth['uid'];
                $auth['expiry']    =    $data['lasttime']    =    SYS_TIME;
                $data['logcount']    =    array('exp','logcount+1');
                $auth['ip']    =    $data['lastip']    =    get_client_ip();
                $User->save($data);
//原因在于:没有添加数据到数据库 导致在验证的时候 提示失败!
                M('Sessions')->add($auth);

                $this->assign("jumpUrl",U('Center/Index/index'));
                $this->success('登录成功!');
                exit;
            }
        }
    }
最佳答案
评论() 相关
后面还有条评论,点击查看>>