欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ajax驗(yàn)證用戶名和密碼的實(shí)例代碼

 更新時(shí)間:2016年05月15日 14:51:17   作者:君灬莫邪  
這篇文章主要為大家詳細(xì)介紹了ajax驗(yàn)證用戶名和密碼的實(shí)例代碼,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家介紹了ajax驗(yàn)證用戶名和密碼的具體代碼,供大家參考,具體內(nèi)容如下

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("請(qǐng)輸入用戶名和密碼!");
   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('用戶名或密碼錯(cuò)誤!');
        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加密,把你的密碼和數(shù)據(jù)庫(kù)名稱(chēng)修改成你自己的即可    

<?php
$yhm1=$_POST['user'];
 $mm1=$_POST['password'];
@ $dp=new mysqli('localhost','root','你的密碼','你的數(shù)據(jù)庫(kù)名稱(chēng)');
$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();
 
?>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論