PHP to determine if a user is logged in _php tutorial

Source: Internet
Author: User
To determine the user login is mainly divided into several processes, the first step is to save the data to the session after the user has successfully logged in, and then when the user access needs to login user rights to determine whether the session is empty, if not the login success. Let's look at an example

To determine the user login is mainly divided into several processes, the first step is to save the data to the session after the user has successfully logged in, and then when the user access needs to login user rights to determine whether the session is empty, if not the login success. Let's look at an example

Session_Start ();

if (GetConfig ("Chatroom_admin") ==$_post["username"]&&getconfig ("Chatroom_adminpassword") ==md5 ($_post[" Password "]))
{
Login successful, register session
Session_register ("Administrator");
if (Isset ($_session["Hack_num"))
{
Session_unregister ("Hack_num");
}
$_session["Administrator"] = "yes";
Header ("location:main.php");
Exit
}
Else
{
if ($_session["Hack_num"]== "")
{
Session_register ("Hack_num");
$_session["Hack_num"] = 1;
}
Else
{
$_session["Hack_num"] + +;

}
Header ("Location:.. /notice.php?id= ". Admin_login_lost);
Exit
}
?>

See the Red No, there is the user login successfully saved to the session[' Hack_num ' face.

This page first determines whether the user is logged in correctly, or, if not logged in, goes to the login page.
Session_Start ();
if ((! $user _id) or (! $user _array[hack_num]) or (! $user _array[hack_num])) {
Header ("location:login.php3");
}
?>

The above code is used to determine whether session[' Hack_num ' has a value, there is a successful login.

This site original reprint annotated source http://www.bKjia.c0m/phper/php.html

http://www.bkjia.com/PHPjc/632039.html www.bkjia.com true http://www.bkjia.com/PHPjc/632039.html techarticle To determine the user login is mainly divided into several processes, the first step is to save the data to the session after the user has successfully logged in, and then when the user access needs to login user rights to determine whether the session ...

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