Php + js + mysql-like webQQ-& lt; 1 & gt; email Verification

Source: Internet
Author: User

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> 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]
<? Php
Header ('content-Type: text/html; charset = GB2312 '); // encoding method setting
Include ("conn. php ");
$ Email = $ _ GET ["email"];
$ Len = strlen ($ email );
If ($ email = null)
{
Echo "<font color = red size = 2px> * the email address cannot be blank! </Font> ";
}
Else
{
If ($ len> 50)
{
Echo "<font color = red size = 2px> * the email cannot exceed 50 characters! </Font> ";
}
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 "<font color = red size = 2px> * this email address has been used! </Font> ";
}
Else
{
Echo "<font color = green size = 2px> * Email available! </Font> ";
}

}
Else
{
Echo "<font color = red size = 2px> * This mailbox is unavailable! </Font> ";
}
}
}
?>
<? Php
Header ('content-Type: text/html; charset = GB2312 '); // encoding method setting
Include ("conn. php ");
$ Email = $ _ GET ["email"];
$ Len = strlen ($ email );
If ($ email = null)
{
Echo "<font color = red size = 2px> * the email address cannot be blank! </Font> ";
}
Else
{
If ($ len> 50)
{
Echo "<font color = red size = 2px> * the email cannot exceed 50 characters! </Font> ";
}
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 "<font color = red size = 2px> * this email address has been used! </Font> ";
}
Else
{
Echo "<font color = green size = 2px> * Email available! </Font> ";
}
 
}
Else
{
Echo "<font color = red size = 2px> * This mailbox is unavailable! </Font> ";
}
}
}
?>
 
After studying mailbox verification, I think other verification should be easy! (To be continued)

 

From wyzhangchengjin123


 

Related Article

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.