PHP Simple Session Class Code _php tutorial

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

  • 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.