Are there any security concerns to consider when using header() for page redirection in PHP?

When using header() for page redirection in PHP, one security concern to consider is ensuring that the input used in the redirection is properly sanitized to prevent header injection attacks. To mitigate this risk, it is recommended to validate and sanitize the input before using it in the header() function to prevent any malicious input from being injected.

// Validate and sanitize the input before using it in header() function
$redirectUrl = filter_var($_GET['redirect_url'], FILTER_SANITIZE_URL);

// Perform additional validation if needed
if (filter_var($redirectUrl, FILTER_VALIDATE_URL)) {
    header("Location: " . $redirectUrl);
    exit();
} else {
    // Handle invalid input
    echo "Invalid redirect URL";
}