Copy Code code 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 ()
{
}
}
?>
Approximate usage
Example:
Log In page: $session = Session::getobject ();
$session->set_ture (); If $row [' password '] = =
Next page:
Copy Code code 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