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
- Is using GD and Image functions the recommended approach for adding a copyright watermark to images uploaded through a PHP form?
- How can PHP developers effectively leverage PHP's built-in functions and libraries for numerical operations?
- How can strings be correctly concatenated in PHP to ensure proper formatting and functionality?