ajax 사용자 이름과 비밀 번 호 를 검증 하 는 인 스 턴 스 코드
1.ajax 주체 부분
var xmlrequest;
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
xmlrequest=new XMLHttpRequest();
}
else if(window.ActiveXObject){
try{
xmlrequest=new ActiveXObject("Msxm12.XMLHTTP");
}
catch(e){
try{
xmlrequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
}
function login(){
createXMLHttpRequest();
var user = document.getElementById("yhm").value;
var password = document.getElementById("mm").value;
if(user==""||password==""){
alert(" !");
return false;
}
var url = "check.php?user="+user+"&password="+password;
xmlrequest.open("POST",url,true);
xmlrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlrequest.onreadystatechange = function(){
if(xmlrequest.readyState == 4){
if(xmlrequest.status==200){
var msg = xmlrequest.responseText;
if(msg=='1'){
alert(' !');
user="";
password="";
return false;
}
else{
window.location.href="index1.html";
}
}
}
}
xmlrequest.send("user="+user+"&password="+password);
}
2.html 코드
<input placeholder=" " autofocus="" type="text"name="username">
<input placeholder=" " type="password" name="password">
<button id="dl" onclick="login()"> </button>
3.sha1 암호 화 를 사용 합 니 다.비밀번호 와 데이터베이스 이름 을 자신의 것 으로 바 꾸 면 됩 니 다.
<?php
$yhm1=$_POST['user'];
$mm1=$_POST['password'];
@ $dp=new mysqli('localhost','root',' ',' ');
$yhm2=sha1($yhm1);
$mm2=sha1($mm1);
$query="select * from zhuce where yhm='$yhm2' and mm='$mm2'";
$result=$dp->query($query);
$num=$result->num_rows;
if(!$num){
echo "1";
}
$dp->close();
?>
이상 은 본문의 전체 내용 이 므 로 여러분 의 학습 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Javascript Ajax에 대한 간단한 연습저는 약 4년 동안 프로그래밍 개인 튜터로 일한 경험이 있습니다. 약 5년 전에 " "이라는 제목의 페르시아어로 내 웹사이트에 블로그 게시물을 올렸고 사람들이 저에게 전화하기 시작했습니다. 나는 항상 사람들을 가르치...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.