电脑安全

您当前的位置:主页 > 电脑安全 >

[Php]再冲动下发个SessionHandle[memcache实现]-网络编程

来源:[db:来源]标题:   方法    编辑:电脑技术全能网 时间:2019-09-21 12:23

原标题:[Php]再冲动下发个SessionHandle[memcache实现]-网络编程
   <?php/***session处置器*memcache完成*@authorMoXieSysTem128@GMail.Com*/classSessionHandlerextendsMemcache{public$_sessionId;#session编号public$_sessionExpire;#session过时时光public$_sessionIsQuery;publicfunction__construct(){$this->_sessionExpire=600;$this->connect(''localhost'',11211);}/***猎取全部定位字段**//***读取Session**@returnunknown*/publicfunctiongetSession($snKey){$returnInfo=$this->get($snKey);$this->_sessionIsQuery=(bool)$returnInfo;return$returnInfo;}/***拔出新的Session*/publicfunctioninsertSession($snKey,$value){return$this->set($snKey,$value,0,$this->_sessionExpire);}/***更新session信息**@returnunknown*/publicfunctionupdateSession($snKey,$value){#修正语句return$this->set($snKey,$value,0,$this->_sessionExpire);}/***删除Session**@returnunknown*/publicfunctiondelSession($snKey){return$this->delete($snKey,0);}/***删除过时Session**@returnunknown*/publicfunctionexpireSession(){returntrue;}/***session启动器**/publicfunctionon_session_start(){$this->_sessionSite=1;$this->_sessionId=session_id();returntrue;}/***session停止*/publicfunctionon_session_end(){return$this->expireSession();}/***读取方式**@paramunknown_type$key*/publicfunctionon_session_read($key){return$this->getSession($key);}/***写入方式**@paramunknown_type$key*@paramunknown_type$value*/publicfunctionon_session_write($key,$value){$this->getSession($key);if($this->_sessionIsQuery){$this->updateSession($key,$value);}else{$this->insertSession($key,$value);}returntrue;}/***烧毁方式**@paramunknown_type$key*/publicfunctionon_session_destroy($key){return$this->delSession();}/***过时方式**@paraminteger$maxLifeTime*/publicfunctionon_session_gc($maxLifeTime){return$this->expireSession();}}$sessionHandler=newSessionHandler();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);?>

上一篇:php流程控制 break continue-网络编程

下一篇:没有了