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'];
(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里面存储的验证码 匹对成功 ,则静如下一步判断 }
(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); }
(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'); }
(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)
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'); }
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!