文章目录

jQuery - ajax

jQuery

$.ajax({
            url: '/数据处理页面',
            type: 'POST',
            dataType: 'json',
            data: login,
            success: function (data) {
                if (data.code == 200) {
                    window.location.href = "/验证成功后的跳转页";
                } else {
                    errorDis(data.info);//返回错误提示
                    //alert(data.info);
                    return false;
                }
            }
        })

php

/**
     * 登录信息验证
     */
    public static function checkloginmsgAction()
    {
        $memberModel = new Model_Member();
        $arr['username'] = $_REQUEST['username'];
        $arr['password'] = $_REQUEST['pwd'];
        $code = $_REQUEST["code"];//验证码
        if ($code !== $_SESSION["memberCode"]) {//验证码校验
            exit(json_encode(array('code'=>-1,'info'=>"验证码不正确")));
        }
        //当使用用户名登录时
        if(!(preg_match("/^1[34578]{1}\d{9}$/",$_REQUEST['username']))&&!(preg_match( "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i", $_REQUEST['username'] ))){
        $whereArr[] = array('username', $arr['username']);
        $whereArr[] = array('password', md5($arr['password']));
        $memberdetail = $memberModel->getMember('*', $whereArr);
            if ($memberdetail[0]['username'] != '') {
            //登录权限查询,0:待审核;1:审核;2:审核失败
                if ($memberdetail[0]['checked'] == 0) {
                    exit(json_encode(array('code' => -1, 'info' => "该用户没有登录权限")));
                }
            //个人信息保存到session
            $_SESSION['memberuser'] = $memberdetail[0]['username'];
            $_SESSION['memberid'] = $memberdetail[0]['uid'];
            $updateMemberArr['logincount'] = $memberdetail['logincount'] + 1;
            $updateMemberArr['ip'] = self::nowip();
            $updateMemberArr['logintime'] = time();
            $sql = "update ##__member set logincount='{$updateMemberArr['logincount']}',ip='{$updateMemberArr['ip']}',logintime='{$updateMemberArr['logintime']}' where id='{$memberdetail['id']}'";
            Core_Db::query($sql);
            exit(json_encode(array('code' => 200)));
            } else {
                exit(json_encode(array('code' => -1, 'info' => '用户名或密码错误')));
            }
            //当使用邮箱登录时
        } elseif (preg_match( "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i", $_REQUEST['username'] )) {
            $whereArr[] = array('email', $arr['username']);
            $whereArr[] = array('password', md5($arr['password']));
            $memberdetail = $memberModel->getMember('*', $whereArr);
            //登录权限查询,0:待审核;1:审核;2:审核失败
            if ($memberdetail[0]['checked'] == 0) {
                exit(json_encode(array('code' => -1, 'info' => "该用户没有登录权限")));
            }
            if ($memberdetail[0]['email'] != '') {
                exit(json_encode(array('code' => 200)));
            } else {
                exit(json_encode(array('code' => -1, 'info' => '邮箱或密码错误')));
            }
        } elseif (preg_match("/^1[34578]{1}\d{9}$/",$_REQUEST['username'])) {//当使用手机号登录时
            $whereArr[] = array('phone', $arr['username']);
            $whereArr[] = array('password', md5($arr['password']));
            $memberdetail = $memberModel->getMember('*', $whereArr);
            //登录权限查询,0:待审核;1:审核;2:审核失败
            if ($memberdetail[0]['checked'] == 0) {
                exit(json_encode(array('code' => -1, 'info' => "该用户没有登录权限")));
            }
            if ($memberdetail[0]['phone'] != '') {
                exit(json_encode(array('code' => 200)));
            } else {
                exit(json_encode(array('code' => -1, 'info' => '手机号或密码错误')));
            }
        }
    }
demo
返回文章列表 文章二维码 打赏
本页链接的二维码
打赏二维码
期待你的评论