I have a simple POST script that I need to return to the page that was doing the Posting.
Is there any way to do it like this?
if($done)
{
//go to page
}
Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php . You can also specify relative URLs.
You should redirect with a location header after every post, because otherwise when the user presses the refresh button, it will send again the same form... Btw. if you want to do proper work, you should try out a php framework instead of this kind of spaghetti code...
The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client).
Redirecting Browserphp header("Location: http://www.example.com/"); ?> The following command will redirect the browser window to the given location as soon as the command is executed. Please note that Location starts with capital L, some browsers might not redirect if small l is used.
if ($done)
{
header("Location: /url/to/the/other/page");
exit;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With