Ec (2); & lt ;? Php & nbsp; ** & nbsp; * & nbsp; session processor & nbsp; * & nbsp; memcache & nbsp; Implementation & nbsp; * & nbsp; @ author & nbsp; MoXie & nbsp; SysTem128@GMail.Com & nbsp; * & nbsp; class & nbsp; SessionHandler & nbs script ec (2); script
/**
* Session Processor
* Memcache implementation
* @ Author MoXie SysTem128@GMail.Com
*/
Class SessionHandler extends Memcache
{
Public $ _ sessionId; # session ID
Public $ _ sessionExpire; # session expiration time
Public $ _ sessionIsQuery;
Public function _ construct ()
{
$ This-> _ sessionExpire = 600;
$ This-> connect ('localhost', 11211 );
}
/**
* Retrieve 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 statements
Return $ this-> set ($ snKey, $ value, 0, $ this-> _ sessionExpire );
}
/**
* Delete A Session
*
* @ Return unknown
*/
Public function delSession ($ snKey)
{
Return $ this-> delete ($ snKey, 0 );
}
/**
* Delete expired sessions
*
* @ Return unknown
*/
Public function expireSession ()
{
Return true;
}
/**
* Session Initiator
*
*/
Public function on_session_start ()
{
$ This-> _ sessionSite = 1;
$ This-> _ sessionId = session_id ();
Return true;
}
/**
* Session termination
*/
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 );
?>