What are the potential risks or security concerns when using header() for page redirection in PHP?

When using header() for page redirection in PHP, one potential risk is that it can be vulnerable to header injection attacks if user input is not properly validated. To mitigate this risk, always validate and sanitize user input before using it in the header function to prevent malicious redirections.

// Validate and sanitize user input before using it in header function
$user_input = filter_var($_GET['redirect_url'], FILTER_SANITIZE_URL);
header("Location: " . $user_input);
exit();