abstract:<?phpnamespace app\index\controller;use think\Controller;class Login extends Controller{public function index(){return $this->fetch();}}在 application\inde
<?php
namespace app\index\controller;
use think\Controller;
class Login extends Controller
{
public function index()
{
return $this->fetch();
}
}
在 application\index\view 新建 login 文件夾,然后在其內(nèi)新建 index.hml
form 表單的提交地址填寫的地址是 login控制的 dologin
// 處理登錄邏輯
public function doLogin()
{
$param = input('post.');
if(empty($param['user_name'])){
$this->error('用戶名不能為空');
}
if(empty($param['user_pwd'])){
$this->error('密碼不能為空');
}
// 驗(yàn)證用戶名
$has = db('users')->where('user_name', $param['user_name'])->find();
if(empty($has)){
$this->error('用戶名密碼錯誤');
}
// 驗(yàn)證密碼
if($has['user_pwd'] != md5($param['user_pwd'])){
$this->error('用戶名密碼錯誤');
}
// 記錄用戶登錄信息
cookie('user_id', $has['id'], 3600); // 一個小時有效期
cookie('user_name', $has['user_name'], 3600);
$this->redirect(url('index/index'));
}
Correcting teacher:韋小寶Correction time:2019-03-10 14:23:06
Teacher's summary:寫的還是很不錯的 有兩行注釋沒有注釋了哦 登錄這一塊的驗(yàn)證還是比較重要的