Ec (2); phpajax user registration check code index. php: & lt; tr & gt; & nbsp; & amp; nbsp; & lt; tdwidth & quot; 25% & quot; class & quot; altbg1 & quot; & script ec (2); script
Php ajax user registration detection code
Index. php: copy the PHP content to the clipboard. PHP code:
User name *
Js: ajax. js: copy the PHP content to the clipboard var xmlHttp;
Function createXMLHttpRequest ()
{
If (window. XMLHttpRequest)
{
XmlHttp = new XMLHttpRequest (); // mozilla Browser
}
Else if (window. ActiveXObject)
{
Try
{
XmlHttp = new ActiveX0bject ("Msxml2.XMLHTTP"); // old IE version
}
Catch (e)
{}
Try
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP"); // new version of IE
}
Catch (e)
{}
If (! XmlHttp)
{
Window. alert ("XMLHttpRequest object instance cannot be created ");
Return false;
}
}
}
Php ajax user registration detection code
Function startRequest (username)
{
CreateXMLHttpRequest (); // Edit
XmlHttp. open ("GET", "ckuser. php? Name = "+ username, true );
XmlHttp. onreadystatechange = handleStateChange;
XmlHttp. send (null );
}
Function handleStateChange ()
{
If (xmlHttp. readyState = 4)
{
If (xmlHttp. status = 200)
{
// Alert ("response from the server:" + xmlHttp. responseText );
If (xmlHttp. responseText = "true "){
Document. getElementById ("ckuser"). innerHTML = 'this user name is registered ';
}
Else if (xmlHttp. responseText = "false ")
{
Document. getElementById ("ckuser"). innerHTML = 'detected pass ';
}
}
}
}
Ckuser. php ajax user registration detection code
PHP code:
//
// Require_once "globals. php ";
Require_once "config. inc. php ";
// Require_once 'common/common. php ';
$ Username = $ _ GET ["name"];
$ Con = @ mysql_connect ("$ dbserver", "$ dbuser", "$ dbpass") or die ("unable to connect to the database! ");
Mysql_query ("set names gbk ");
Mysql_select_db ("$ dbname", $ con) or die ("You cannot select a database! ");
$ Query = "select id from hj_member where username = '". $ username ."';";
$ Res = mysql_query ($ query );
If (mysql_num_rows ($ res )! = 0)
{
Echo "true ";
} Else
{
Echo "false ";
}
?>