tp5引用cookie

登入

    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}

 

posted @ 2020-04-26 14:22  静静地开始  阅读(565)  评论(0)    收藏  举报