PHP ??? ?? ??? ??? ??? ?? ???
??? ?? ???
???? ??? ????.
??? ??? ????.
<?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ù)庫 $code = $_POST["code"]; if($user == "" || $psw == "") { //用戶名或者密碼其中之一為空,則彈出對話框,確定后返回當(dāng)前頁的上一頁 echo "<script>alert('請輸入用戶名或者密碼!'); history.go(-1);</script>"; }else if($code != $_SESSION[' ver_code']){ echo "<script>alert('驗證碼不正確,請重新輸入!'); history.go(-1);</script>"; } else { //確認(rèn)用戶名密碼驗證碼不為空,則連接數(shù)據(jù)庫 $conn = mysqli_connect("localhost","root","root");//數(shù)據(jù)庫帳號密碼為安裝數(shù)據(jù)庫時設(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>"; } ?>
?? ??:
? ????? ??? ????? ???? ???? ??? ????- ????? post ???? ??? $_POST["hidden"]? ????? ?????. ???? ??? ??? ????? ???? ???? ?? ???? ?????. ??? ?????? ??? ??????.
- ??? ?? ????(trim() ??? ???? ?? ??? ?????, md5() ??? ???? ????? ????) ?? ??? ?????. ?? ??? ????? ?????. ?? ?? ??? ??
- post ???? ??? ?? ?? ?? ??? ??? ???? ?? ?? ?? ???? ?????. , ?? ??? ???? ??? ???? ???? ???? ?? ??
??????? ????, ??? ??????? ????, ?? ??? ????, ??????? ?????. ??? ??? ????, ??? ??? ????? ??????? ????? ?????. ???? ??? ??? ???? ????? ???? ??? ???? ?????. ??? ???? ????, ???? ?? ?? ???? ?????. ???, ?? ???? ????