登入
public function index(){
if(request()->isPost()){
$data = input(‘post.‘);
$val = [
‘name‘ => ‘require|max:25‘,
‘pass‘ => ‘require‘,
‘captcha‘ => ‘require|captcha‘
];
$may = [
‘name.require‘ => ‘用户名为空‘,
‘name.max‘ => ‘用户名少于25‘,
‘pass.require‘ => ‘密码为空‘,
‘captcha.require‘ => ‘验证码为空‘,
‘captcha.captcha‘ => ‘验证码错误‘
];
$validate = new Validate($val,$may);
$isok = $validate->check($data);
if(!$isok){
$this->error($validate->getError());
};
$whe[‘name‘] = trim($data[‘name‘]);
$whe[‘pasd‘] = md5($data[‘pass‘]);
$in = db(‘kehu‘)->where($whe)->find();
if(empty($in)){
$this->error(‘用户名或密码错误!‘);
}else{
cookie(‘admin‘,$in[‘id‘]);
$this->redirect(‘index/index‘);
}
};
主页php
$id = cookie(‘admin‘);
$info = db(‘kehu‘)->where(‘id‘, $id)->find();
$this->assign(‘info‘, $info);
html
{empty name="$info.name"}
<a href="#" data-toggle="modal" data-target="#myModal1">
<span class="fa fa-unlock-alt" aria-hidden="true"></span>登录</a>
{else /}
<a href="#" >
<span class="fa fa-unlock-alt" aria-hidden="true"></span>{$info.name}</a>
{/empty}
原文:https://www.cnblogs.com/wangzihao147/p/12779257.html