PHP user registration login system login processing page
Login processing page
The flow chart is as follows:
The code is as follows:
<?php session_start(); //登錄處理界面 logincheck.php //判斷是否按下提交按鈕 if(isset($_POST["hidden"]) && $_POST["hidden"] == "hidden") { //將用戶名和密碼存入變量中,供后續(xù)使用 $user = trim($_POST["username"]);//trim()函數(shù)移除字符串兩側(cè)的空白字符 $psw = md5(trim($_POST["userpwd"]));//密碼使用md5()加密一次,存入數(shù)據(jù)庫(kù) $code = $_POST["code"]; if($user == "" || $psw == "") { //用戶名或者密碼其中之一為空,則彈出對(duì)話框,確定后返回當(dāng)前頁(yè)的上一頁(yè) echo "<script>alert('請(qǐng)輸入用戶名或者密碼!'); history.go(-1);</script>"; }else if($code != $_SESSION[' ver_code']){ echo "<script>alert('驗(yàn)證碼不正確,請(qǐng)重新輸入!'); history.go(-1);</script>"; } else { //確認(rèn)用戶名密碼驗(yàn)證碼不為空,則連接數(shù)據(jù)庫(kù) $conn = mysqli_connect("localhost","root","root");//數(shù)據(jù)庫(kù)帳號(hào)密碼為安裝數(shù)據(jù)庫(kù)時(shí)設(shè)置 if(mysqli_errno($conn)){ echo mysqli_errno($conn); exit; } mysqli_select_db($conn,"userdb"); mysqli_set_charset($conn,'utf8'); $sql = "select username,userpwd from user where username = '$user' and userpwd = '$psw'"; $result = mysqli_query($conn,$sql); $num = mysqli_num_rows($result); if($num) { echo "<script>alert('成功登錄'); window.location.href='index.php';</script>"; } else { echo "<script>alert('用戶名或密碼不正確!');history.go(-1);</script>"; } } } else { echo "<script>alert('提交未成功!');</script>"; } ?>
Code explanation:
Enter when you click login on the login page Login processing page
Determine whether the $_POST["hidden"] passed in the post method exists. If it does not exist, it will prompt that the submission was unsuccessful and return to the login interface. If it exists, continue.
Get the passed value (use the trim() function to filter blank characters, and use the md5() function to encrypt the password), and then determine whether it is empty. If it is empty, a prompt will pop up. Return to the login interface. If it is not empty, continue
Determine whether the verification code value passed by the post method is equal to the verification code value that previously existed in the session. If they are not equal, it will prompt that the verification code is incorrect. , return to the login page, if equal, continue to execute
- ## Connect to the database, select the database we created, set the character set, query the database through the user name and password, and determine whether the user name and password are Exists in the database. If it does not exist, it will prompt that the user name or password is incorrect and return to the login page. If it exists, it will prompt successful login and jump to the homepage