[PHP] Impulse issued a sessionhandle[memcache implementation]

Source: Internet
Author: User


? 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 );
?>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.