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