? PHP
/* *
* Session Processor
* Memcache Implementation
* @author Moxie SysTem128@GMail.Com
*/
class Sessionhandler extends Memcache
{
Public $_sessionid ; # Session Number
Public $_sessionexpire ; # Session Expiration Time
Public $_sessionisquery ;
Public function __construct ()
{
$this -> _sessionexpire = - ;
$this -> Connect ( '' localhost '' , 11211 );
}
/* *
* Get all positioning fields
*
*/
/* *
* Read session
*
* @return Unknown
*/
Public function GetSession ( $snKey )
{
$returnInfo = $this -> Get ( $snKey );
$this -> _sessionisquery = (BOOL) $returnInfo ;
return $returnInfo ;
}
/* *
* Insert a new session
*/
Public function Insertsession ( $snKey , $value )
{
return $this -> Set ( $snKey , $value , 0 , $this -> _sessionexpire);
}
/* *
* Update session information
*
* @return Unknown
*/
Public function Updatesession ( $snKey , $value )
{
# Modify Statement
return $this -> Set ( $snKey , $value , 0 , $this -> _sessionexpire);
}
/* *
* Delete Session
*
* @return Unknown
*/
Public function Delsession ( $snKey )
{
return $this -> Delete ( $snKey , 0 );
}
/* *
* Delete Expired session
*
* @return Unknown
*/
Public function expiresession ()
{
return true ;
}
/* *
* Session Initiator
*
*/
Public function On_session_start ()
{
$this -> _sessionsite = 1 ;
$this -> _sessionid = session_id ();
return true ;
}
/* *
* Session Terminated
*/
Public function On_session_end ()
{
return $this -> Expiresession ();
}
/* *
* Read method
*
* @param unknown_type $key
*/
Public function On_session_read ( $key )
{
return $this -> GetSession ( $key );
}
/* *
* Write method
*
* @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 ;
}
/* *
* Destruction Method
*
* @param unknown_type $key
*/
Public function On_session_destroy ( $key )
{
return $this -> delsession ();
}
/* *
* Expiration method
*
* @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 );
?>