💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
控制器 \Application\Admin\Controller\PublicController.class.php ~~~ <?php namespace Admin\Controller; use Think\Controller; class PublicController extends Controller { //登录验证 public function login(){ if(IS_POST){ $map['account'] = I('account'); //用户名 $map['password'] = md5(I('password')); //密码 $info = D('Admin')->where($map)->find(); if (!$info) { $this->ajaxReturn(['code'=>0,'msg'=>'账户或密码错误']); } if ($info['status'] == 0) { $this->ajaxReturn(['code'=>0,'msg'=>'登录失败,账号被禁用']); } session('aid',$info['id']); //管理员ID session('account',$info['account']); //保存登录信息 $data['id'] = $info['id']; //用户ID $data['login_time'] = time(); //最后登录时间 $data['login_count'] = $info['login_count'] + 1; M('Admin')->save($data); $notes = session('account').'于'.date('Y-m-d H:i:s',time()).'成功登录浩卓后台管理系统。'; // addmanagelog(1,$notes); D('AdminLog')->update(1,$notes); $this->ajaxReturn(['code'=>1,'msg'=>'登录成功']); // $this->success('验证成功,正在跳转到首页',U('Index/index')); }else{ if(session('aid')){ $this->redirect('Index/index'); } $this->display(); } } } ~~~ 登录页面 \Application\Admin\View\Public\login.html ~~~ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome="> <title>后台管理系统</title> <link rel="stylesheet" href="__PUBLIC__/Admin/css/login.css"> <script src="__PUBLIC__/Admin/js/jquery-1.9.1.js"></script> <script src="__PUBLIC__/Common/Layer/layer.js"></script> </head> <body> <div class="main"> <div class="login"> <form id="loginform" method="post"> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="30%" class="tdleble">用户名:</td> <td width="60%"> <input type="text" name="account" class="infoInput" maxlength="20" value="" placeholder="请输入用户名" /></td> </tr> <tr> <td height="36" class="tdleble">密&nbsp;&nbsp;&nbsp;码:</td> <td> <input type="password" name="password" class="infoInput" value="" placeholder="请输入密码" /></td> </tr> <tr> <td>&nbsp;</td> <td> <input type="submit" name="submit" value="登&nbsp;&nbsp;&nbsp;录" class="subbottom" /></td> </tr> </table> </form> </div> </div> <script>// 刷新验证码 $(function() { var verifyimg = $(".reloadverify").attr("src"); $(".reloadverify").click(function() { if (verifyimg.indexOf('?') > 0) { $(".reloadverify").attr("src", verifyimg + '&random=' + Math.random()); } else { $(".reloadverify").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random()); } }); $("#loginform").submit(function(e){ var res = $(this).serialize(); var url = "{:U('Public/login')}"; $.ajax({ url: url, data: res, type: 'post', success:function(data){ if (data.code == 1) { layer.alert(data.msg,{icon:6},function (index) { layer.close(index); window.location.href = "{:U('Index/index')}"; }); } else{ layer.alert(data.msg,{icon:5},function (index) { layer.close(index); window.location.reload(); }); } } }); return false; // 阻止表单跳转 }); }); </script> </body> </html> ~~~