Is it possible to specify a target when redirecting to a different URL in PHP?
When redirecting to a different URL in PHP, it is possible to specify a target by including it in the URL itself. This can be achieved by appending the target as a query parameter to the URL. For example, if you want to redirect to "example.com" with a specific target page "page2.php", you can construct the URL as "example.com?page=page2.php".
<?php
// Specify the target page
$targetPage = "page2.php";
// Redirect to the specified target page
header("Location: example.com?page=$targetPage");
exit;
?>
Related Questions
- How can PHP sessions be effectively utilized to retain data between requests?
- How can PHP developers ensure that their file upload scripts are secure and functioning correctly?
- What are some alternative methods or functions in PHP that can be used to extract and process data from external URLs without encountering permission issues?