摘要:<?php namespace app\admin\controller; use think\Controller; use think\facade\Session; class Login extends Controller { public function&n
<?php namespace app\admin\controller; use think\Controller; use think\facade\Session; class Login extends Controller { public function index(){ if (request()->isPost()){ $data = input(''); $username = $data['username']; $password = md5($data['password']); $user = model('user')->where('username',$username)->find(); if ($user != true){ $info = ['res' => 0,'msg' => '用户名不存在']; }elseif($password != $user['password']){ $info = ['res' => 0,'msg' => '密码错误']; }else{ $info = ['res' => 1,'msg' => '登录成功']; Session::set('username',$user['username']); } return $info; }else{ return $this->fetch(); } } public function LoginOut(){ Session::delete('username'); $this->redirect('index'); } }
批改老师:西门大官人批改时间:2019-04-20 13:28:23
老师总结:查询数据之前,最好先校验一下用户输入的username是否有值