サマリー:<?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' => '密碼錯(cuò)誤']; }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'); } }
添削の先生:西門大官人添削時(shí)間:2019-04-20 13:28:23
先生のまとめ:查詢數(shù)據(jù)之前,最好先校驗(yàn)一下用戶輸入的username是否有值