A total of two pages, register.php and verify.php
1. User Registration Form register.php
Copy the Code code as follows:
2. Create User Data tables users
Copy the Code code as follows:
CREATE TABLE IF not EXISTS ' users ' (
' id ' int (one) not NULL auto_increment,
' Status ' varchar (not NULL),
' username ' varchar (not NULL),
' Password ' varchar (not NULL),
' Email ' varchar (not NULL),
' Activationkey ' varchar (+) not NULL,
PRIMARY KEY (' id '),
UNIQUE KEY ' username ' (' username '),
UNIQUE KEY ' email ' (' email '),
UNIQUE KEY ' Activationkey ' (' Activationkey ')
) Engine=myisam DEFAULT charset=latin1 auto_increment=9;
3. Create Verification Code user registration information into the data sheet
We use the status ' verify ' to represent users who have not yet been activated.
Copy the Code code as follows:
$activationKey = Mt_rand (). Mt_rand (). Mt_rand (). Mt_rand (). Mt_rand ();
$username = mysql_real_escape_string ($_post[username]);
$password = mysql_real_escape_string ($_post[password]);
$email = mysql_real_escape_string ($_post[email]);
$sql = "INSERT into users (username, password, email, activationkey, status) VALUES (' $username ', ' $password ', ' $email ', ' $a Ctivationkey ', ' verify ') ";
4. Send Verification Code
Copy the Code code as follows:
echo "an email had been sent to $_post[email] with an activation key. Please check the your mail to complete registration. ";
# #Send Activation Email
$to = $_post[email];
$subject = "yourwebsite.com registration";
$message = "Welcome to our website!\r\ryou, or someone using your email address, have completed registration at Yourwebsite . com. You can complete registration by clicking the following link:\rhttp://www. Yourwebsite.com/verify.php? $activationKey \r\rif This is a error, ignore this e-mail and you'll be removed from our Maili ng list.\r\rregards,\ yourwebsite.com Team ";
$headers = ' from:noreply@ yourwebsite.com '. "\ r \ n".
' reply-to:noreply@ yourwebsite.com '. "\ r \ n".
' x-mailer:php/'. Phpversion ();
Mail ($to, $subject, $message, $headers);
5. Verify the Activation Code verify.php
If the verification code is the same, the user is activated.
Copy the Code code as follows:
$queryString = $_server[' query_string ');
$query = "SELECT * from users";
$result = mysql_query ($query) or Die (Mysql_error ());
while ($row = Mysql_fetch_array ($result)) {
if ($queryString = = $row ["Activationkey"]) {
echo "congratulations!". $row ["username"]. "Is now the proud new owner of a yourwebsite.com account.";
$sql = "UPDATE users SET activationkey = ', status= ' activated ' WHERE (id = $row [id])";
if (!mysql_query ($sql)) {
Die (' Error: '. mysql_error ());
}
Here, the user has fully activated the account, you can jump to the page after the landing interface
}
}//End of while