How can a registration confirmation link be implemented in PHP?

To implement a registration confirmation link in PHP, you can generate a unique token for each user during registration and include it in the confirmation link sent to their email. When the user clicks on the link, you can verify the token and mark the user as confirmed in the database.

// Generate a unique token for the user during registration
$token = bin2hex(random_bytes(16));

// Save the token in the database along with the user's information

// Send the confirmation email with a link containing the token
$confirmationLink = "http://example.com/confirm.php?token=" . $token;
$message = "Click the following link to confirm your registration: $confirmationLink";
// Use mail() function or a library like PHPMailer to send the email

// In confirm.php, verify the token and mark the user as confirmed in the database
$token = $_GET['token'];
// Query the database to check if the token exists and mark the user as confirmed