I've read somewhere that using a META refresh for a redirect, is not a recommended practice.
As far as I understand header( "refresh:0;url=$url" );
in PHP, and <meta http-equiv="refresh" content="0;url=$url/" />
as a META tag in HTML, are both considered a META refresh which would return this header:
HTTP/1.x 200 OK
...
Refresh: 0;url=$url
Assuming I don't want to use a JS redirect, would it be possible to use another recommended practice redirect such as 301 or 302, while still running the following elements in the redirect page, such as the following message and a certain script?
<?php
$url = "could-not-get-a-foo-parameter-at-all-error-monitoring-page.html";
if(isset($_POST['foo'])){
switch ($_POST['foo']) {
case "a":
$url = "http://www.aaa.com/";
break;
case "b":
$url = "http://www.bbb.com/";
break;
default:
$url = "foo-parameter-exists-but-is-wrong-error-monitoring-page.html";
break;
}
}
header( "refresh:0;url=$url" );
?>
<!doctype html>
<html>
<head>
<style>
.message {
color:blue;
}
</style>
</head>
<body>
<div class="message">Redirecting, Please hold on...</div>
<script>
something
</script>
You can't invoke PHP once the page has rendered (no more PHP until another server request), so any form of delayed redirect is impossible that way. You're stuck with JS or the meta header refresh (obviously, you can't use PHP variables in pure HTML and you need more than 0 seconds if you actually want to keep the page up for a while before redirecting).
Use a refresh value of something other than 0: header( "refresh:10;url=$url" );
Short answer. No.
a PHP header redirect, <?php header('location: [url]');?>
will give you the 302 header, which the browser will redirect to, but you cannot also send HTML that will ever be seen by the user since as soon as the browser sees that header, it will immediately redirect and won't display the rest of the content. you CAN change the timeout on the meta redirect as suggested by TML, but that will leave the page up until the timed interval has passed, or you can create a interstitial page with your message, and let them know how long until the redirect happens, with an option to click "here" now for an immediate redirect.
Use all 3 options as it will gracefully degrade.
Not sure if it's still an issue but some browsers wouldn't send a referer header for 0 second meta-refresh and instead needed a little time to set it.