How can the expiration time of a registration confirmation link be effectively managed in PHP?

When sending registration confirmation links via email, it is important to set an expiration time to ensure the security of the process. To effectively manage the expiration time of a registration confirmation link in PHP, you can include a timestamp in the link URL and compare it with the current time when the link is accessed. If the timestamp is older than the specified expiration time, the link should be considered invalid.

// Generate registration confirmation link with expiration time
$expiration_time = time() + 3600; // 1 hour expiration
$confirmation_link = "http://example.com/confirm.php?token=abc123&expires=$expiration_time";

// Validate confirmation link
if(isset($_GET['expires']) && $_GET['expires'] >= time()) {
    // Link is still valid, process registration confirmation
} else {
    // Link has expired, show error message
    echo "Error: Confirmation link has expired.";
}