PHP ?? ??? ???? ??? ??
??? ??: ?? ?? HTML ??? ???????
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>歡迎登錄</title> <style type="text/css"> *{margin: 0px;padding: 0px;} body{background:#eee;} #div{width:300px;height:400px;background:#B1FEF9;margin:0 auto;margin-top:150px; border-radius:20px;} h3{margin-left:48px;padding-top:60px;} h4{margin-left:120px;padding-top:60px;font-size: 18px;} #cnt{width:280px;height:370px;margin-left:33px;padding-top:60px;} .sub{width:70px;height:30px;border:1px solid #fff;background:#eee; margin-left:28px;margin-top:20px;} .sub1{ width:70px;height:30px;border:1px solid #fff;background:#eee;margin-left:150px;margin-top:20px;} </style> </head> <body> <div id="div"> <h3>歡迎登陸后臺(tái)管理系統(tǒng)</h3> <div id="cnt"> <form method="post" action="main.php"> 用戶名:<input type="text" placeholder="請輸入用戶名" name="username"> <br><br> 密 碼:<input type="password" placeholder="請輸入密碼" name="password"> <br><br> <input type="submit" value="登錄" class="sub"> </form> </div> </div> </body> </html>
?? main.php? ???????. ?? main.php? ??? ?????.
??? ? ???? ? ???? ?? ?? ?? ??? ? ????? ???. ?? ?? ??? ???? ???.
?? ??? ??? ?? ?? ?? ??? ?????. ??
$name = $_POST['username'];
$pwd = md5($_POST['password'])$_SESSION['name']=$name;
$_SESSION['pwd'] =$pwd; ???? ??? ?? ??????? ?????. ??????? ???? ??? ??? ???? ??? ??? ??? ????? ???? ???. ???? ? ???? $sql = "????? *? ?????. ??? ??? ??='$name' ? ????='$pwd'"; $info = mysql_query($sql);
$row = mysql_fetch_row($info);
?? ?? $row? ????, ???? ?? ???? ??? ????. ???? ????? ???? ???? ????, ??? ??? ???? ???? ?? ??????
if($row){
echo "<script>alert( '??? ??');location.href='message .php';</script>"; }else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ?? ?? ? ? ? ? ? ? ? ? ?? ?? ?? ?? off ‐ ‐‐‐‐ ? ? echo "<script>alert('??? ??')</ script>""
? ? ???"<script>location.href='login.php';</script>"; //??? ??, ?? ???? ??
main.php ?? ??? ??? ????. ???:
<?php session_start(); require_once('conn.php'); $name = $_POST['username']; $pwd = md5($_POST['password']); $_SESSION['name']=$name; $_SESSION['pwd']=$pwd; $sql = "select * from user where username='$name' and password='$pwd'"; $info = mysql_query($sql); $row = mysql_fetch_row($info); if($row){ echo "<script>alert('登錄成功');location.href='message.php';</script>"; }else{ echo "<script>alert('登錄失敗')</script>"; echo "<script>location.href='login.php';</script>"; //登錄失敗,跳轉(zhuǎn)到另外一個(gè)頁面 } ?>