P
P
PetrovVK2020-01-14 22:00:03
PHP
PetrovVK, 2020-01-14 22:00:03

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' );
}

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
W
wisgest, 2020-01-15
@PetrovVK

What am I doing wrong?

Redirect to Locationalways fires before any processing of the response body, Refreshalways fires after the document has finished loading.

A
Alexander, 2020-01-14
@AleksandrB

You redirect to the same page (via Location) with a get parameter, then check it

if (isset($_GET('id'))) {
// redirect
}

F
FanatPHP, 2020-01-14
@FanatPHP

No need to engage in perversions
Do a redirect right away and don't fool yourself.

E
eyyuioa, 2020-01-15
@eyyuioa

$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");

L
Lev Zabudkin, 2020-01-15
@zabudkin

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 question

Ask a Question

731 491 924 answers to any question