Php + js + mysql-like webQQ-& lt; 1 & gt; email verification _ PHP Tutorial

Source: Internet
Author: User
Php + js + mysql-like webQQ-& amp; lt; 1 & amp; gt; email verification. Recently, I used php + js + mysql to design a webQQ-like course. I have learned a lot. now I will summarize the key technologies for you to learn and exchange. 1. when registering an email verification user, I recently used php + js + mysql to design a webQQ-like course. I have learned a lot. now I will summarize the key technologies, for everyone to learn and exchange.

<1> email verification

When a user registers, he or she will enter the email address in the text box, in this case, the onblur and onchange events in the text box use the Ajax brushless new technology to determine whether the email address entered by the user is legal and whether it conflicts with the registered email address.

Js code

[Html]
Function checkEmail (Email)
{
Var xmlhttp;
If (window. XMLHttpRequest)
{// Code for IE7 +, Firefox, Chrome, Opera, Safari
Xmlhttp = new XMLHttpRequest ();
If (xmlhttp. overrideMimeType)
{// Set the MIME category
Xmlhttp. overrideMimeType ("text/xml ");
}
}
Else
{// Code for IE6, IE5
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Var url = "checkEmail. php? Email = "+ document. getElementById (" email "). value; // go to checkEmail. php for verification.
Xmlhttp. open ("GET", url, true );
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
Document. getElementById ("error1"). innerHTML = xmlhttp. responseText;
}
}
Xmlhttp. send (null );
}
Function checkEmail (Email)
{
Var xmlhttp;
If (window. XMLHttpRequest)
{// Code for IE7 +, Firefox, Chrome, Opera, Safari
Xmlhttp = new XMLHttpRequest ();
If (xmlhttp. overrideMimeType)
{// Set the MIME category
Xmlhttp. overrideMimeType ("text/xml ");
}
}
Else
{// Code for IE6, IE5
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Var url = "checkEmail. php? Email = "+ document. getElementById (" email "). value; // go to checkEmail. php for verification.
Xmlhttp. open ("GET", url, true );
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
Document. getElementById ("error1"). innerHTML = xmlhttp. responseText;
}
}
Xmlhttp. send (null );
}

PHP code

[Php]
Header ('content-Type: text/html; charset = GB2312 '); // encoding method setting
Include ("conn. php ");
$ Email = $ _ GET ["email"];
$ Len = strlen ($ email );
If ($ email = null)
{
Echo "* email cannot be blank! ";
}
Else
{
If ($ len> 50)
{
Echo "* the email address cannot exceed 50 characters! ";
}
Else
{
If (eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + .) + [a-z] {2, 3} $ ", $ email) // use a regular expression in php to verify the email address.
{
$ SQL = "select * from user where email = '$ email'"; // connect to the database to check whether the mailbox is used
$ Result = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ result );
If ($ num> 0)
{
Echo "* this email address is already in use! ";
}
Else
{
Echo "* email available! ";
}

}
Else
{
Echo "* this mailbox is unavailable! ";
}
}
}
?>
Header ('content-Type: text/html; charset = GB2312 '); // encoding method setting
Include ("conn. php ");
$ Email = $ _ GET ["email"];
$ Len = strlen ($ email );
If ($ email = null)
{
Echo "* email cannot be blank! ";
}
Else
{
If ($ len> 50)
{
Echo "* the email address cannot exceed 50 characters! ";
}
Else
{
If (eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + .) + [a-z] {2, 3} $ ", $ email) // use a regular expression in php to verify the email address.
{
$ SQL = "select * from user where email = '$ email'"; // connect to the database to check whether the mailbox is used
$ Result = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ result );
If ($ num> 0)
{
Echo "* this email address is already in use! ";
}
Else
{
Echo "* email available! ";
}

}
Else
{
Echo "* this mailbox is unavailable! ";
}
}
}
?>

After studying mailbox verification, I think other verification should be easy! (To be continued)

From wyzhangchengjin123


Bytes. 1. when the user is registered, the email address will be...

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.