What is a common method for implementing user registration with email activation in PHP?

One common method for implementing user registration with email activation in PHP is to generate a unique activation code for each user during registration. This activation code is then included in a link sent to the user's email address. When the user clicks on the activation link, their account is activated in the database.

// Generate a unique activation code
$activation_code = md5(uniqid(rand(), true));

// Save the activation code in the database along with the user's information
$query = "INSERT INTO users (username, email, password, activation_code) VALUES ('$username', '$email', '$password', '$activation_code')";
// Execute the query

// Send an email to the user with the activation link
$to = $email;
$subject = 'Activate Your Account';
$message = 'Click the following link to activate your account: http://www.yourwebsite.com/activate.php?code=' . $activation_code;
$headers = 'From: yourwebsite@example.com';
mail($to, $subject, $message, $headers);