欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

简单的SESSION管理类

程序员文章站 2022-03-21 20:08:12
...
一个很基础的单例模式的SESSION管理类。
start_session();
        return self::$instance;
    }
 
    public function start_session(){
        if($this->session_state == self::SESSION_NOT_STARTED){
            $this->session_state = session_start();
        }
        return $this->session_state;
    }
 
    public function __set($name,$value){
        $_SESSION[$name] = $value;
    }
 
    public function __get($name){
        if(isset($_SESSION[$name])){
            return $_SESSION[$name];
        }
    }
 
    public function __isset($name){
        return isset($_SESSION[$name]);
    }
 
    public function __unsset($name){
        unset($_SESSION[$name]);
    }
 
    public function destroy(){
        if($this->session_state == self::SESSION_STARTED){
            $this->session_state = !session_destroy();
            unset($_SESSION);
            return !$this->session_state;
        }
 
        return false;
    }
}