Answer the question
In order to leave comments, you need to log in
How to refresh the page and then redirect?
Required: if the new_invoice button is pressed, then first refresh the page, and then make a redirect. No matter what I did - refresh does not work, even though it is the first ...
if (isset($_POST['new_invoice']) ) {
header( 'Refresh: 0');
header( 'Location: invoice.php?id=111' );
}
Answer the question
In order to leave comments, you need to log in
What am I doing wrong?
Location
always fires before any processing of the response body, Refresh
always fires after the document has finished loading.
You redirect to the same page (via Location) with a get parameter, then check it
if (isset($_GET('id'))) {
// redirect
}
No need to engage in perversions
Do a redirect right away and don't fool yourself.
$url = "/index.php";
$time = 1; #time in seconds
header("Refresh: $time; url=$url");
Makes a redirect, and then redirects to the desired page, but I strongly do not recommend using Refresh, as it confuses search engine bots, is not supported by all browsers, and apparently you use it as a wonderful crutch.
As mentioned earlier, use Location for such purposes.
header("Location: $url");
if (isset($_POST['new_invoice']) ) {
//////////////////////////////////////// header( 'Refresh: 0');
header( 'Location: invoice.php?id=111' );
die();
}
if (isset($_POST['new_invoice']) ) {
//////////////////////////////////////// header( 'Refresh: 0');
header( 'Location: invoice.php?id='.$_POST['new_invoice'] );
die();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question