Home >Backend Development >PHP Tutorial >PHP determines whether the user is logged in_PHP tutorial

PHP determines whether the user is logged in_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:57:591391browse

Determining user login is mainly divided into several processes. The first step is to save the data into the session after the user successfully logs in. Then when the user accesses the user permissions that require logged in, it is judged whether the session is empty. If not, log in. success. Let’s look at an example

There are several processes to determine user login. The first step is to save the data into the session after the user successfully logs in. Then when the user accesses the user permissions that require logged in, it is judged whether the session is empty. , if not, the login is successful. Let’s take a look at an example

session_start();

if(getconfig("chatroom_admin")==$_post["username"]&&getconfig("chatroom_adminpassword")==md5($_post["password"]))
{
//Log in successfully, 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;
}
?>

If you see the red one, it means that the user successfully logged in and saved the data to the session['hack_num'] page.

//This page first determines whether the user is logged in correctly. If not logged in, it 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. If it does, the login is successful.

Original reprints on this site indicate the source http://www.bKjia.c0m/phper/php.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632039.htmlTechArticleThere are several processes to determine user login. The first step is to save the data to the session after the user successfully logs in. Then when the user accesses the user permissions that require logged in, it is judged whether the session is...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn