Copy codeThe Code is as follows:
<? Php
Class session
{
Static $ sessionObject;
/* $ _ SESSION ['user'] = 0, don't work.
* = 1, he is really user.
*/
Private function _ construct ()
{
If (! (Isset ($ _ SESSION ['user']) & $ _ SESSION ['user'] = 0 ))
Session_set_cookie_params (3600 );
Session_start (); // Initialize14} 15 private function _ clone ()
{
}
Public static function getObject ()
{
If (! Self: $ sessionObject instanceof self)
$ SessionObject = new session ();
Return $ sessionObject;
}
Public function set_false ()
{
$ _ SESSION ['user'] = 0; // for PHP> = 5
}
Public function set_true ()
{
If (isset ($ _ SESSION ['user'])
$ _ SESSION ['user'] = 1;
Else
$ This-> error ();
}
Public function get_status ()
{
Return $ _ SESSION ['user'];
}
Public function end_session ()
{
Session_destroy ();
}
Public function error ()
{
}
}
?>
General Usage
Example:
Log in page: $ session = session: getObject ();
$ Session-> set_ture (); // if $ row ['Password'] =
Next page:
Copy codeThe Code is as follows:
$ Session = session: getObject ();
If ($ session-> get_status ())
//... The user is really
Else
//....
Log out: $ session = session: getObject ();
$ Session-> end_session ();
Get_status () returns whether the current user is logged on effectively.