设为首页 加入收藏

TOP

登录(ajax提交数据和后台校验)
2017-10-10 11:33:19 】 浏览:4827
Tags:登录 ajax 提交 数据 后台 校验

1.前台ajax数据提交

<form id="login_form" action="" method="POST">
    <div class="login_frame" style="position:relative";>
        <div class="login_gl" style="margin-top:35px;">
            <span class="login_wz" >后台管理系统</span>
        </div>

        <div class="login_user">
            <input id="username" name="username" type="text" placeholder="请输入您的用户名" value=""  style="width:100%;height:32px;border-style:none;font-size:16px;color:#959595;"/>
        </div>

        <div class="login_user">
            <input id="password" name="password" type="password" placeholder="请输入您的密码" value=""  style="width:100%;height:32px;border-style:none;font-size:16px;color:#959595;"/>
        </div>

        <div id="login_btn" class="login_log">
            <span style="font-size:16px;">登录</span>
        </div>
    </div>
   </form>
</div>
<script type="text/java script">
    $("#login_btn").click(function(){
       var username = $.trim($("#username").val());
       var password = $.trim($("#password").val());
        if(username == ""){
            alert("请输入用户名");
            return false;
        }else if(password == ""){
            alert("请输入密码");
            return false;
        }
        //ajax去服务器端校验
        var data= {username:username,password:password};
        
        $.ajax({
            type:"POST",
            url:"__CONTROLLER__/check_login",
            data:data,
            dataType:'json',
            success:function(msg){
                //alert(msg);
                if(msg==1){
                      window.location.href = "{:U('Index/personal')}";   
                }else{
                    alert("登录失败,请重试!");
                }
            }
        });
});    
</script>

2.后台校验:

  * */
    public function check_login(){
        $password=I('param.password');
        $username=I('param.username');
        $data["name"]=$username;
        $user=M('systemuser');
        $list=$user->where($data)->find();
        $return=0;
        if($list!=""){
            if($list['password']==md5($password) && $list['status'] == 1){
                //登录时间和登录IP
                $public = new PublicController();
                $lastlogonip=$public->ip_address();
                            
                $time=$time=date("Y-m-d H:i:s", time());
                $where=array('id'=>$list['id']);
                
                $user->where($where)->save(array('lastlogonip'=>$lastlogonip,'lastlogontime'=>$time));
                $this->login($list);
                $return=1;//登录成功
            }
        }else{
            $return=2;//登录失败
        }
        $this->ajaxReturn($return);
    }

******************************************************************************************

退出登录:

退出登录:<a href="{:U('Login/Login')}"> <img src="/Public/images/tuichu.png"> </a>

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP_环境配置_python脚本_2017 下一篇PHP_环境配置_python脚本_2017

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目