PHP source code

Source: Internet
Author: User
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 ";
}


?>

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.