Home > Backend Development > PHP Tutorial > PHP method to implement background entry/exit verification judgment

PHP method to implement background entry/exit verification judgment

小云云
Release: 2023-03-22 18:26:02
Original
2107 people have browsed it

In the process of website development, what we often encounter and often use is login and registration, and back-end personal information management. Of course, these contents are inseparable from verification. If there is no system Judgment and verification of ideas, then this website is unsafe. Well, the following is the verification stage of entering and exiting the background in the background development I learned today:

(1) First get The form value filled in the current login page:

$username = $_POST['username'];
$password = md5($_POST['password']);
$verify = $_POST['verify'];
$verify_s = $_SESSION['verify'];
Copy after login

(2) The first is the verification code judgment, and the verification code judgment is inseparable from the use of $_SESSION:

if(strtolower($verify) == strtolower($verify_s)){
    //如果输入的验证码和session里面存储的验证码 匹对成功 ,则静如下一步判断
}
Copy after login

(3) Then there is the user Comparison of name and password:

//匹配查询的语句:
$sql = "select * from imooc_admin where username = '{$username}' and password = '{$password}'";
// 匹配用户名和密码
$con= connect(); //数据库连接
$res = checkAdmin($con,$sql); //数据库查询
function checkAdmin($con,$sql){
    return fetchOne($con,$sql);
}
Copy after login

(4) If the username and password match successfully, set session (cookie) and automatically enter the background page:

if(!!$res){
    $_SESSION['adminName'] = $res['username'];
    $_SESSION['adminId'] = $res['id'];
    alertMes('登陆成功','main.php');
}else{
    alertMes('登陆失败','login.php');
}
Copy after login

(5) After Jingru background, You can choose to exit the background: (The link to exit the background needs to add a key-value pair similar to the following)

Exit

After obtaining through $_REQUEST['act'], execute the exit operation.

5-1. Clear the current session (cookie)

5-2. Jump to the homepage

function logout() { 
    $_SESSION = array(); 
     if(isset($_COOKIE[session_name()])){ 
         setcookie(session_name(),'',time()-1); 
     } 
     session_destroy(); 
     alertMes('退出成功','login.php'); 
 }
Copy after login

The above is the detailed content of PHP method to implement background entry/exit verification judgment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template