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("請輸入用戶名和密碼!");
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ù)庫名稱修改成你自己的即可
<?php
$yhm1=$_POST['user'];
$mm1=$_POST['password'];
@ $dp=new mysqli('localhost','root','你的密碼','你的數(shù)據(jù)庫名稱');
$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();
?>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。
相關(guān)文章
深入淺析AjaxFileUpload實(shí)現(xiàn)單個(gè)文件的 Ajax 文件上傳庫
jQuery.AjaxFileUpload.js是一款jQuery插件,用于通過ajax上傳文件。本文給大家介紹AjaxFileUpload實(shí)現(xiàn)單個(gè)文件的 Ajax 文件上傳庫,對此感興趣的朋友一起學(xué)習(xí)吧2016-04-04
Ajax獲取數(shù)據(jù)然后顯示在頁面的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狝jax獲取數(shù)據(jù)然后顯示在頁面的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08
活到老學(xué)到老學(xué)習(xí)AJAX跨域(三)
學(xué)習(xí)AJAX其實(shí)有個(gè)很重要的應(yīng)用,就是為了執(zhí)行另外幾個(gè)站點(diǎn)的ASP,返回結(jié)果。通過本文給大家介紹ajax跨域相關(guān)知識(shí),需要的朋友參考下2016-02-02
IIS7中Ajax.AjaxMethod無效的原因及解決方法
使用Ajax.AjaxMethod方法在asp.net的服務(wù)器下一切正常,用iis的時(shí)候,js中總是cs類找不到,具體的解決方法如下,遇到類似情況的朋友可以參考下2013-07-07
django獲取ajax的post復(fù)雜對象的實(shí)現(xiàn)方法
這篇文章主要介紹了django獲取ajax的post復(fù)雜對象的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-10-10

