21,887
社区成员
发帖
与我相关
我的任务
分享
<body>
<div data-role="page" id="login">
<div data-role="header">
<h1>用戶登入</h1>
</div>
<div data-role="content">
<form id="form1" name="form1" method="post" action="#">
<div data-role="fieldcontain">
<input type="text" name="username" id="username" placeholder="用戶名">
<input type="password" name="password" id="password" placeholder="密碼">
<input type="submit" data-role="button" id="submit" value="登入" onClick="ajax_login()">
</div>
</form>
<p>沒有帳號?<a href="#register" data-transition="slide">點擊註冊</a></p>
</div>
<div data-role="footer" style="text-align: center" data-position="fixed">
<p>CopyRight ©2020</p>
</div>
</div>
<script>
function ajax_login() {
var username = $("#username").val();
var password = $("#password").val();
var urlweb = "loading_check.php";
if (username==""){
layer.open({content: '請輸入用戶名!',btn: '好的'});
document.getElementById("username").focus();
return false;
}
if (password==""){
layer.open({content: '請輸入密碼!',btn: '好的'});
document.getElementById("password").focus();
return false;
}
$.ajax({
type: "POST",
url: urlweb,
dataType:'json',
data: {user:username,pass:password},
beforeSend: function () {
document.getElementById("submit").value = "正在登入中";
},
success: function (json) {
if(json.Loge==3){
document.getElementById("submit").value = "登入成功";
window.self.location='admin/input.html';
}else if(json.Loge==1){
layer.open({content: '帳戶名錯誤',skin: 'footer'});
document.getElementById("txtname").focus();
document.getElementById("submit").value = "重新登入";
}
}
});
}
</script>
</body>
include("conn/conn.php");
$user=$_REQUEST['username'];
$pass=md5($_REQUEST['password']);
$sql = mysql_query("select * from user where Nmber='".$user."' and Pass='".$pass."' ");
if($result = mysql_fetch_array($sql)){
echo json_encode(array ('Loge'=>3));
}else{
echo json_encode(array ('Loge'=>1));
}