??? ??? ??? ?? ??
?? ???? ????? ??? ???? ???? ??? ???? login.html ??? ?? ??? ????? ??????. ??? ?????? ??? admin? ???? ??? ??? ????? ?? ??? ???? ??????. ?? ????? ??? ??? ????????.
?? ??? ?? ?? ???? ?????.
???? ?? ????? ??? ???? ???? ? ??? ? ? ????.
?? ?? ?????? ??? ???? ???: config.php
POST? ?? ???? ?????. ???? ?? ?? ????? Trim() ??? ??????.
$username = trim($_POST["username"]);//用戶(hù)名 $password = trim($_POST["password"]);//密碼 $code = $_POST["code"]; //驗(yàn)證碼
??? ??? ????? ??????, ?? ??? ????? ?????.
if($username == "") { echo"<script type='text/javascript'>alert('請(qǐng)?zhí)顚?xiě)用戶(hù)名');location='login.html'; </script>"; } if($password == "") { //echo "請(qǐng)?zhí)顚?xiě)用戶(hù)名<br>"; echo"<script type='text/javascript'>alert('請(qǐng)?zhí)顚?xiě)密碼');location='login.html'; </script>"; } if($code != $_SESSION['authcode']) { echo "<script type='text/javascript'>alert('驗(yàn)證碼錯(cuò)誤!');location='login.html';</script>"; }
??? ??? ??? ????? ??????? ??? ? ??? ??? ????? ????? ?????.
$sql = "select * from admin where username='".$username."' and password='".$password."'"; $result = mysqli_query($link, $sql); $rows = mysqli_fetch_array($result); if($rows) { //echo "驗(yàn)證成功!<br>"; $expire_time=time()+7200; setcookie('admin_id',$rows['id'],$expire_time); setcookie('username',$rows['username'],$expire_time); echo "<script type='text/javascript'>alert('登陸成功');location='index.php';</script>"; } else { //echo "用戶(hù)名或者密碼錯(cuò)誤<br>"; echo "<script type='text/javascript'>alert('用戶(hù)名或者密碼錯(cuò)誤');location='login.html';</script>"; //echo "<a href='login.html'>返回</a>"; }
???? ??? ? ?????? ?? ?????? ??? ??? ??? ??? ?????.