PHP PHP5 Session Wraper类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP PHP5 Session Wraper类相关的知识,希望对你有一定的参考价值。
class Session
{
var $__setting;
function __construct($name = 'FuseLogic')
{
$this->__setting = new open();
$this->__setting->name = $name;
$this->__setting->_session = array();
$this->__setting->space = '___';
if(!isset($_SESSION)) session_start();
if(count($_SESSION)>0)
{
foreach($_SESSION as $name => $value)
{
$temp = explode($this->__setting->space,$name);
if($temp[0] == $this->__setting->name)
{
$name = str_replace($this->__setting->name.$this->__setting->space,'',$name);
$this->__setting->_session[$name] = $value;
}
}
}
}
private function name($name = null)
{
return $this->__setting->name.$this->__setting->space.$name;
}
public function __get($name)
{
return @$this->__setting->_session[$name];
}
public function __set($name,$value)
{
$this->__setting->_session[$name] = $value;
$name = $this->name($name);
$_SESSION[$name] = $value;
}
public function __isset($name)
{
return isset($this->__setting->_session[$name]);
}
function clean()
{
if(count($this->__setting->_session)>0)
{
foreach($this->__setting->_session as $name => $value)
{
$name = $this->name($name);
unset($_SESSION[$name]);
}
$this->__setting->_session = array();
}
}
function destroy()
{
$this->__setting->_session = array();
session_destroy();
}
function fromArray($a=null)
{
if(is_array($a))
{
foreach($a as $k => $v) $this->$k = $v;
}
}
function toArray()
{
return $this->__setting->_session;
}
}
以上是关于PHP PHP5 Session Wraper类的主要内容,如果未能解决你的问题,请参考以下文章
关于PHP5 Session生命周期介绍
php7和php5区别
PHPSession-完全PHP5之session篇
当 register_globals 关闭时 PHP5 $_SESSION 不工作
windows php5.5安装redis扩展,并用redis存储session
yii cookie ,session 操作