thinkphp登录操作模块

原创 2019-03-10 14:04:54 390
摘要:<?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 文件夹,然后在其内新建 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('密码不能为空');

}

// 验证用户名

$has = db('users')->where('user_name', $param['user_name'])->find();

if(empty($has)){

$this->error('用户名密码错误');

}

// 验证密码

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'));

}


批改老师:韦小宝批改时间:2019-03-10 14:23:06
老师总结:写的还是很不错的 有两行注释没有注释了哦 登录这一块的验证还是比较重要的

发布手记

热门词条