摘要:<?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
老師總結(jié):查詢數(shù)據(jù)之前,最好先校驗一下用戶輸入的username是否有值