Jump to content

Echo Message Before Page Redirect


polarus

Recommended Posts

Hello,

I am trying to echo a message before redirecting the visitor to another page.

The destination is a variable. This is what i have so far:

 

<?php
if (array_key_exists($_GET[id],$links))
{
$red = $links[$_GET[id]];
header("HTTP/1.1 301 Moved Permanently;");
header("Refresh:3; url=$red");
echo "You will be redirected to..";
}
else { 
header("Location: http://www.example.com");
}
exit(); ?>

 

The problem is that it works in Firefox, but not IE. In IE it will work if there is no message and no delay, like the code below:

<?php
if (array_key_exists($_GET[id],$links))
{
$red = $links[$_GET[id]];
header("HTTP/1.1 301 Moved Permanently;");
header("Location: $red");

}
else { 
header("Location: http://www.example.com");
}
exit(); ?

 

Does anybody have any idea, what is wrong with this code?

Thank you in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/249038-echo-message-before-page-redirect/
Share on other sites

But the message is simply telling them that they're being redirected...

 

You "can't" have output and a Location: header at the same time. The user won't see the message. So pick what you want more: the automatic redirection or the message.

If you want the message then redirect using other means, such as a refresh or a JavaScript window.setTimeout() delay.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.