Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Php to write post-registration Email activation verification

Shulou Source: shulou.com Published: 2022-06-03 05:40:05 09月22日 Update

This article will explain in detail how to use Php to write Email activation verification after registration. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

A total of two pages are required, register.php and verify.php

1. User registration form register.php

The copy code is as follows:

User name:

Password:

Email:

two。 Create a user data table Users

The copy code is as follows:

CREATE TABLE IF NOT EXISTS `users` (

`id`int (11) NOT NULL auto_increment

`status` varchar (20) NOT NULL

`username` varchar (20) NOT NULL

`password` varchar (20) NOT NULL

`email` varchar (20) NOT NULL

`activationkey` varchar (100) 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 CAPTCHA and store the user registration information in the data table

We use the status' verify' to represent users who have not been activated.

The copy code is 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','$activationKey', 'verify')"

4. Send verification code

The copy code is as follows:

Echo "An email has been sent to $_ post [email] with an activation key. Please check 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, has completed registration at YOURWEBSITE.com. You can complete registration by clicking the following link:\ r http://www.YOURWEBSITE.com/verify.php?$activationKey\r\rIf this is an error, ignore this email and you will be removed from our mailing 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.

The copy code is 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 ()

}

/ / at this point, the user has fully activated the account, and you can jump to the interface after login.

}

} / / end of while

On "how to use Php to write Email activation verification after registration" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Code user activation authentication article data more user registration table page good practical same two information content password not yet datasheet article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Xiaomi MariaDB MySQL