The Boolean Flag TRUE OR FALSE in the header()
determines whether you want the current header()
to replace a previous one. If you want multiple headers, set it to FALSE. By default, this is TRUE... This means any subsequent header()
replaces the Previous One. The 3rd Parameter is the HTTP RESPONSE CODE.
To explicitly set the Response Code to 307, You can use PHP http_response_code($code)
. Combining the 2, You can have something like this:
// EXPLICITLY SET RESPONSE CODE TO 307
http_response_code(307);
// REFRESH & REDIRECT TO page.php
// IN FACT; THERE IS NO NEED FOR THE http_response_code(307) ABOVE
// THIS ONE LINE DOES IT ALL IN ONE GO...
header("refresh:2; url=page.php", FALSE, 307);
If you increased the refresh
to (say) 15 so that you have enough time to look into the the Browser's Web-Developer Tools
(under the Networks Tab
), You'd notice that the HTTP Response Code of 307
was indeed set & sent....
To pass some data from the current page to page.php
, You have 2 Options. Pass the Data via $_GET
like so:
<?php
$url = urlencode("page.php?user=web&password=developper&city=bronx");
header("refresh:2; url={$url}", FALSE, 307);
Or You could use Session like so:
<?php
//FIRST CHECK IF SESSION EXIST BEFORE STARTING IT:
if (session_status() == PHP_SESSION_NONE || session_id() == '') {
session_start();
}
// SET SOME DATA INTO THE $_SESSION (TO BE USED IN page.php, ETC.)
$_SESSION['user'] = 'web';
$_SESSION['pass'] = 'developper';
$_SESSION['city'] = 'bronx';
header("refresh:2; url=page.php", FALSE, 307);