您当前的位置: 首页 > 

苗先生的PHP记录

暂无认证

  • 0浏览

    0关注

    190博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

读取session

苗先生的PHP记录 发布时间:2019-08-17 18:12:56 ,浏览量:0

Session::set(‘admin’,$admin); 在浏览器f12的Application的Cookies里可以直接删除session ~~ ~~ ①设置session 后 可以用一个基类来获取并赋值

$this->_admin = Session::get('admin');
        if(!$this->_admin){
            $this->error('未登录','login/index');
            exit;
        }
        $this->assign('admin',$this->_admin);

②在基类中 设置常量

//在控制其中有一个初始化的方法 protected function _initialize
    protected function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub

        //在公共控制器的初始化方法中,创建一个常量获取session值来判断用户是否登录或已登录
        define('USER_ID',Session::get('user_id'));

        //获取网站配置信息
        $config = $this->getSystem();
        //获取当前请求对象
        $request = Request::instance();
        //查询当前网站开关状态
        $this->getStatus($request,$config);
    }

    //判断用户是否已登录 在后台入口index/渲染调用
    protected function islogin()
    {
        //如果登录常量为NULL,就没有登录
        if(is_null(USER_ID)){
            $this -> error('未登录,无权访问~~~~ ','login/index');
        }
    }
    //如果用户已经登录,将不允许重复登录,直接跳转到主页,在登录渲染调用
    protected function alreadyLogin()
    {
        //如果登录常量为NULL,就没有登录
        if(!is_null(USER_ID)){
            $this -> error('请不要重复登录~~~~ ','index/index');
        }
    }

③ 直接在view读取

{$Request.session.admin.id}
关注
打赏
1665468453
查看更多评论
立即登录/注册

微信扫码登录

0.0443s