polarus Posted October 13, 2011 Share Posted October 13, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/249038-echo-message-before-page-redirect/ Share on other sites More sharing options...
requinix Posted October 13, 2011 Share Posted October 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249038-echo-message-before-page-redirect/#findComment-1279042 Share on other sites More sharing options...
codefossa Posted October 13, 2011 Share Posted October 13, 2011 <?php $site = 'http://example.com'; $wait = 2; // Seconds ?> <meta http-equiv="refresh" content="<?php echo $wait; ?>;url=<?php echo $site; ?>" /> You're being redirected to <?php echo $site; ?>. Quote Link to comment https://forums.phpfreaks.com/topic/249038-echo-message-before-page-redirect/#findComment-1279045 Share on other sites More sharing options...
polarus Posted October 13, 2011 Author Share Posted October 13, 2011 I deleted header("HTTP/1.1 301 Moved Permanently;"); and did a echo "<meta http-equiv='Refresh' content='2; URL=$red'>"; and it worked ok, in both IE and Firefox Thank you for your replies. Quote Link to comment https://forums.phpfreaks.com/topic/249038-echo-message-before-page-redirect/#findComment-1279081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.