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>
實際應用中,使用;調用就行..