使用php+ajax实现登录功能教程-1

php登录源码: 
下面是chklogin.php页面代码: 
<?php 
session_start(); 
$connect=mysql_connect("127.0.0.1","root","123"); 
if(!$connect) 

die(’Could not connect: ’ . mysql_error()); 

mysql_select_db(design,$connect); 
$query="select * from ta_user where user_name =’".$name."’"; 
$result=mysql_query($query) OR die("Unable to connect to MySQL"); 
$rows=mysql_fetch_array($result); 
if($rows[user_password]==$pwd) 


header("Location:login_suss.php?name=".$name.""); 

else 

echo "<table width=’235’ height=’61’ border=’0’ align=’center’>"; 
echo "<tr><td height=’29’>用户名或密码错误!</td></tr>"; 
echo "<tr><td height=’29’>请点击<a href=’javascript:history.go(-1);’>这儿</a>重新输入!"; 
echo "</td></tr>"; 
echo "</table>"; 


?>

登陆验证的AJAX代码示例:

<script language="javascript"> 
function getXMLHTTPRequest() 

var xRequest=null; 
if (window.XMLHttpRequest) 

xRequest=new XMLHttpRequest(); 

else if (typeof ActiveXObject != "undefined") 

xRequest=new ActiveXObject("Microsoft.XMLHTTP"); 

return xRequest; 

function Ajax(url) 

AjaxObj = getXMLHTTPRequest(); 
AjaxObj.onreadystatechange = processRequest; 
AjaxObj.open("post",url,true); 
AjaxObj.setRequestHeader(’Content-type’,’application/x-www-form-urlencoded’); 
AjaxObj.send("name"+name); 


function processRequest() 


if(AjaxObj.readyState == 4) 

if(AjaxObj.status == 200) 

if(AjaxObj.responseText != "") 

document.getElementById("show").innerHTML=""; 
//alert(AjaxObj.responseText); 

document.getElementById("show").innerHTML=AjaxObj.responseText; 



else 

alert("您所请求的页面有异常。") 


else 

document.getElementById("show").innerHTML="Loading......"; 


</script> 
实际应用中,使用οnclick="Ajax(***.php)";调用就行.. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值