PHP Simple session-Class Code _php basics

Source: Internet
Author: User
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

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.