<html><head> <meta charset="utf-8"><script type="text/javascript" src="jquery-1.7.2.min.js"></script><script type="text/javascript" src="a.js"></script><style type="text/css">body { font:12px/1.6em "宋體" }ul { list-style:none; }li { margin-top:10px; }</style></head><body><h3>會員登陸</h3><div id="login"><form method="post" action="login.php" id="form" name="form"> <ul> <li>名字:<input type="text" name="user" id="user" size="16" maxlength="20"></li> <li>密碼:<input type="password" name="pass" id="pass" size="16" maxlength="20"></li> <li> <input type="submit" style="border:0" /> </li> <li id="confirm"></li> </ul></form></div></body></html>
$(document).ready(function(){ $("#form").submit(function(){ login(); return false; });});function login(){var user = $("#user").val();var pass = $("#pass").val();if (user == ""){ $("#confirm").text("請輸入登陸用戶名"); $("#user").focus(); return false;}if(pass == ""){ $("#confirm").text("請輸入登陸密碼"); $("#pass").focus(); return false;}$.ajax({ type: "POST", url: "login.php", data: "id=" + user + "&p=" + pass, beforeSend: function(){ $("confirm").text("登陸中,請稍候"); }, success: function(msg){ if(msg == "success"){ $("#confirm").text("登陸成功,歡迎" + user + "回來!正在進入你的空間"); }else { $("#confirm").text("沒有此用戶或者密碼不正確!"); } }});}
<?php$p = isset($_POST["p"]) ? $_POST["p"] : $_GET["p"];$id = isset($_POST["id"]) ? $_POST["id"] : $_GET["id"];if($id == "admin" && $p == "admin"){ echo 'success';}?>