What potential security risks should be considered when using email links to redirect users to different pages in PHP applications?

One potential security risk when using email links to redirect users in PHP applications is the possibility of email link manipulation by attackers. To mitigate this risk, it is crucial to validate and sanitize the URL parameters passed through the email link to ensure they are safe and legitimate.

// Validate and sanitize the URL parameter before redirecting
$redirectUrl = filter_var($_GET['redirect_url'], FILTER_VALIDATE_URL);

if ($redirectUrl !== false) {
    header("Location: " . $redirectUrl);
    exit();
} else {
    // Handle invalid URL parameter
    echo "Invalid URL";
}