Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > ajax

ajax验证用户名和密码的实例代码

来源:中文源码网    浏览:154 次    日期:2024-05-17 11:31:20
【下载文档:  ajax验证用户名和密码的实例代码.txt 】


ajax验证用户名和密码的实例代码
本文实例为大家介绍了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代码



3.这里用的是sha1加密,把你的密码和数据库名称修改成你自己的即可
$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();
?>
以上就是本文的全部内容,希望对大家的学习有所帮助。

相关内容