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();
Related Questions
- How can distributing program logic throughout a webpage impact code readability and maintenance?
- How can one verify if emails sent to gmx.de are encrypted when using PHPMailer with TLS enabled?
- How can PHP developers efficiently handle database queries for image galleries to ensure a sequential display of images?