[Php]再冲动下发个SessionHandle[memcache实现]
<script>ec(2);</script>
php
/**
* session处理器
* memcache 实现
* @author MoXie SysTem128@GMail.Com
*/
class SessionHandler extends Memcache
{
public $_sessionId; # session 编号
public $_sessionExpire; # session 过期时间
public $_sessionIsQuery;
public function __construct()
{
$this->_sessionExpire = 600;
$this->connect(''localhost'',11211);
}
/**
* 获取所有定位字段
*
*/
/**
* 读取 Session
*
* @return unknown
*/
public function getSession($snKey)
{
$returnInfo = $this->get($snKey);
$this->_sessionIsQuery = (bool)$returnInfo;
return $returnInfo;
}
/**
* 插入新的Session
*/
public function insertSession($snKey,$value)
{
return $this->set($snKey,$value,0,$this->_sessionExpire);
}
/**
* 更新session信息
*
* @return unknown
*/
public function updateSession($snKey,$value)
{
# 修改语句
return $this->set($snKey,$value,0,$this->_sessionExpire);
}
/**
* 删除Session
*
* @return unknown
*/
public function delSession($snKey)
{
return $this->delete($snKey,0);
}
/**
* 删除过期 Session
*
* @return unknown
*/
public function expireSession()
{
return true;
}
/**
* session 启动器
*
*/
public function on_session_start()
{
$this->_sessionSite = 1;
$this->_sessionId = session_id();
return true;
}
/**
* session 终止
*/
public function on_session_end()
{
return $this->expireSession();
}
/**
* 读取方法
*
* @param unknown_type $key
*/
public function on_session_read($key)
{
return $this->getSession($key);
}
/**
* 写入方法
*
* @param unknown_type $key
* @param unknown_type $value
*/
public function on_session_write($key,$value)
{
$this->getSession($key);
if ($this->_sessionIsQuery)
{
$this->updateSession($key,$value);
}else{
$this->insertSession($key,$value);
}
return true;
}
/**
* 销毁方法
*
* @param unknown_type $key
*/
public function on_session_destroy($key)
{
return $this->delSession();
}
/**
* 过期方法
*
* @param integer $maxLifeTime
*/
public function on_session_gc($maxLifeTime)
{
return $this->expireSession();
}
}
$sessionHandler = new SessionHandler();
session_set_save_handler(
array(&$sessionHandler,''on_session_start''),
array(&$sessionHandler,''on_session_end''),
array(&$sessionHandler,''on_session_read''),
array(&$sessionHandler,''on_session_write''),
array(&$sessionHandler,''on_session_destroy''),
array(&$sessionHandler,''on_session_gc'')
);
unregister_tick_function(''session_write_close'');
session_start();
//$_SESSION[''MoXie''] = ''Wonderfull!'';
//$_SESSION[''SysTem128''] = ''Wonderfull!'';
//session_unregister(''MoXie'');
print_r($_SESSION);
?>
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31