Copy CodeThe code is as follows:
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 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 ();
by Get_status () returns whether the current user is logged in effectively
http://www.bkjia.com/PHPjc/324193.html www.bkjia.com true http://www.bkjia.com/PHPjc/324193.html techarticle Copy the code as follows:? PHP class Session {static $sessionObject;/* $_session[' user '] = = 0, don ' t work. * = = 1, he is really User. */Private Function __construct () {if (...