How can variables be used in the header() function in PHP for redirection?

When using the `header()` function in PHP for redirection, variables can be used by concatenating them within the string passed to the function. This allows for dynamic redirection based on the value of the variables. It is important to ensure that the variables are properly sanitized and validated to prevent security vulnerabilities such as header injection.

// Example of using variables in header() function for redirection
$redirectUrl = "http://example.com/page.php";
header("Location: " . $redirectUrl);
exit();