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...