?? ???? ??? ??? ??? PHP ?? ??
?? ????? ??? ?? ???, ??? ????, ?????? ??? ?? ?? ?? ??? ??????. ?? ????? ??? ??? ???? ????? ?? ????? ??? ?? ???? ?????!
?? login.php ??? ???? ???. ? ??? ??? ???? ?? ? ??? ???? ? ??? ? ????. ???? html ??? ??? ?? ??? php ??? ?? ??? ?? ????. ?? ??? PHP ?? ?? ??? ??? ?? ?? ??? HTML ??? ??? ? ????! ??? ??? ??? ???? ?? ????!
login.php ??? ??? ? ?? ?? ?? ? ?? ??????? ???? ????. ?? ??? ???? ???? ?? ?????!
??? ???? ?? ??? ?? ?? ? ??? ?? ???? session_start()? ????? ???. ??? ??? ?? ??? ??? ? ????. session_start()? ????.
??? ??? ????.
<?php session_start(); // 連接mysql數(shù)據(jù)庫 $link = mysqli_connect('localhost', 'root', 'root'); if (!$link) { echo "connect mysql error!"; exit(); } // 選中數(shù)據(jù)庫 news為數(shù)據(jù)庫的名字 $db_selected = mysqli_select_db($link, 'news'); if (!$db_selected) { echo "<br>selected db error!"; exit(); } // 設(shè)置mysql字符集 為 utf8 $link->query("set names utf8");
?? ??? ??? ??? ???? ???? ????. ???? ???? ??? ??? ??? ??? ????? ???? ?? ?????. ??? ??? ?? ??????? ???? ??? ???? ?????!
<?php $username = $_POST['username'];//獲取用戶名 $password = $_POST['password'];//獲取密碼 $code = $_POST['code'];
post? ?? ???? ???? ??? get? ?? ???? ????? ??? ??? ??? ?? ????. ??? ???? ????!
???? ???? ???? ??? ???? ??????? ???? ??? ????? ???? ???. ? ????? ???? ????? ??? ? ??? ??? ??? ? ????. ??? SQL ?? ??? ????.
<?php if(!empty($_POST)){ // 查詢數(shù)據(jù)庫中是否存在用戶信息 $sql = "select * from user where username = '{$username}' and password = '{$password}'"; $result = mysqli_query($link,$sql); $user = mysqli_fetch_array($result,MYSQL_ASSOC);}
Query ???? ??? ? ? ??? ??? ?????.
if($user){ header("Location: index.php"); }else{ echo "<script>alert('賬戶或者密碼錯誤!重新填寫')</script>"; }
???? ??? ??? ????? ?????? ?? ??? ????. ?? ??? ???? ???. ???? ?? ?? ????? ??????.
? ?? ?? ?? ??? ?????!
?? ?? ?? ??? ???? ???.
if(($_SESSION['authcode']) !== ($code)){ //驗證碼作對比,驗證碼頁面跟輸入的驗證碼對比 echo "<script>alert('驗證碼錯誤!重新填寫')</script>";
??: $_SESSION['authcode'] ??? ??? ??? ???? ?? ??? ????. ??? ????? ???????!
?? ??? ??? ???????!