Using Php+ajax to implement the login feature tutorial

Source: Internet
Author: User
Tags implement connect query

PHP Login Source:
The following is the chklogin.php page code:
<?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= ' border= ' 0 ' align= ' center ' >";
echo "<tr><td height=" > Username or password is wrong! </td></tr> ";
echo "<tr><td height= ' > Please click <a href= ' Javascript:history.go (-1); ' > Here </a> re-enter! ";
echo "</td></tr>";
echo "</table>";

}
?>

Example of an AJAX code for landing verification:

<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 ("The page you are requesting has an exception.) ")
}
}
Else
{
document.getElementById ("Show"). Innerhtml= "Loading ...";
}
}
</script>
In practical application, use; call on the line.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.