What are some potential security risks when using PHP to redirect to a local server?

One potential security risk when using PHP to redirect to a local server is the possibility of an open redirect vulnerability, where an attacker could manipulate the redirect URL to redirect users to malicious websites. To mitigate this risk, always validate and sanitize user input before using it in a redirect function.

// Validate and sanitize the redirect URL before using it
$redirectUrl = filter_var($_GET['redirect'], FILTER_SANITIZE_URL);

// Redirect to the sanitized URL
header("Location: " . $redirectUrl);
exit();