标签:.post url HERE cat script 写用 min use class
前台
<script> function dologin() { var username = $("input[name=‘username‘]").val(); var password = $("input[name=‘password‘]").val(); if (username == ‘‘) { $("#infoerror").text(‘请填写用户名‘); return; } if (password == ‘‘) { $("#infoerror").text(‘请填写密码‘); return; } var data = { ‘username‘: username, ‘password‘: password }; $.post("{:url(‘check‘)}", data, function (res) { if (res.code == 0) { $("#infoerror").text(res.msg); return; } else if (res.code == 1) { layer.msg(res.msg); setTimeout("location.href=‘{:url(‘home/index‘)}‘", 500); } }, ‘json‘); } </script>
后台
public function check() { $username = trim(input(‘post.username‘)); $password = trim(input(‘post.password‘)); if(!$username){ exit(json_encode(array(‘code‘=>0,‘msg‘=>‘请填写用户名‘))); } if(!$password){ exit(json_encode(array(‘code‘=>0,‘msg‘=>‘请填写密码‘))); } //从数据库查询到数组 $data = Db::table(‘admin‘)->where(‘username‘,$username)->find(); //如果查到为空 if(!$data){ exit(json_encode(array(‘code‘=>0,‘msg‘=>‘用户名不存在‘))); } //如果密码匹配 if($data[‘password‘] != md5($username.$password)){ exit(json_encode(array(‘code‘=>0,‘msg‘=>‘密码错误‘))); } //验证通过 //设置session Session::set(‘admin‘,$data); exit(json_encode(array(‘code‘=>1,‘msg‘=>‘登录成功‘))); }
标签:.post url HERE cat script 写用 min use class
原文地址:https://www.cnblogs.com/cl94/p/9121300.html