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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.