首页 > 其他 > 详细

tp5引用cookie

时间:2020-04-26 15:16:37      阅读:69      评论:0      收藏:0      [点我收藏+]

登入

    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}

 

tp5引用cookie

原文:https://www.cnblogs.com/wangzihao147/p/12779257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!