亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

自定義的數(shù)組模擬用戶數(shù)據(jù)庫進行簡單的用戶登錄

asal 2019-05-20 15:42:06 274
abstrak: <!DOCTYPE html> <html> <head> <title>登錄</title> <meta charset="utf-8"> <script type="text/javascript" src="jquer
<!DOCTYPE html>
<html>
<head>
	<title>登錄</title>
	<meta charset="utf-8">
	<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
	<style type="text/css">
 		.content{
 			width: 350px;height: 300px;
 			background-color: #ccc;
 			text-align: center;
 			margin: 100px auto;
 			position: relative;
 		}
 		.content1{
 			/*margin-top: 50px;*/
 			width: 100%;height: 200px;
 			background-color: lightgreen;
 			position: absolute;top: 50px;
 		}

 	</style>
</head>
<body>
	<div class="content">
		<div class="content1">
			 <h3>用戶登錄</h3>
			 	<p>
			 	<label>用戶:</label>
			 	<input type="username" name="username" id="username">
			 </p>
			 <p>
			 	<label>密碼:</label>
			 	<input type="password" name="password" id="password" >
			 </p>
			 <p>
			 	<button onclick="dologin()">登錄</button>
			 </p>
		</div>
 	</div>
</body>
</html>
<script type="text/javascript" href="">

	function dologin(){
		// alert(11);
		//獲取qq輸入的內容;
		var user = $('input[name="username"]').val();
		var pwd = $('input[name="password"]').val();
		if(user == ''){
			alert('請輸入用戶名');
			return;
		}
		if(pwd == ''){
			alert('請輸入密碼');
			return;
		}

		//通過post將數(shù)據(jù)提交到后臺進行驗證;
		$.post('ceshi3.php',{qq:user,pwd:pwd},function(data){
			// console.log(data);
			if(data.code==1){
				alert(data.msg);
			}else{
				alert(data.msg);
				// setTimeout(function(){window.location.href='index.php';},2000);
			}
		},'json')
	}
</script>
?>
<?php 
//接收信息
$qq = $_POST['qq'];
$pwd = $_POST['pwd'];

$data = [
	["username"=>'admin',"password"=>123456],
	["username"=>'luheng',"password"=>111111],
	["username"=>'zhangsan',"password"=>121212],
];

$like = [] ;
foreach($data as $k => $val){
	if(in_array($qq, $val)){
	 $like = $val;
	}
}
//$like是一個數(shù)組
//判斷$like是否有值;
if(!$like){
echo json_encode(['code'=>1,'msg'=>'用戶名錯誤']);
return;
}

//判斷密碼是否存在;
if($like['password'] != $pwd  ){
echo json_encode(['code'=>1,'msg'=>'密碼錯誤']);
return;
}

exit(json_encode(array('code'=>0,'msg'=>'登錄成功')));


 ?>

foreach循環(huán)二維數(shù)組;輸出為多個一維數(shù)組;

in_array可以通過值找到一維數(shù)組;

Guru membetulkan:天蓬老師Masa pembetulan:2019-05-20 16:11:40
Rumusan guru:基本上提到異步交互, 數(shù)據(jù)格式幾乎都是JSON, 一定要關注

Nota Keluaran

Penyertaan Popular