Vernersson Posted November 23, 2007 Share Posted November 23, 2007 Hi, it's the converting from ASP-to-PHP man here again, and I got a question for you guys!Is there any way to do a response.redirect("page.asp") in PHP? The only examples I've found has been code in the <head></head> area and since im working with a site that only includes php in already existing pages this causes an error since you can't have two Headers in the same page and i can't have the redirect code in the default.php since that would make every page that loads within default.php redirect to the same page. Hope you understand and will be able to help me out!Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted November 23, 2007 Share Posted November 23, 2007 If you can't use the header() function, I have a kind of different approach to redirection. Try this: echo "<script type=\"text/javascript\">window.location.href=\"page.asp\"</script>"; Link to comment Share on other sites More sharing options...
boen_robot Posted November 23, 2007 Share Posted November 23, 2007 If you can't use the header() function, I have a kind of different approach to redirection. Try this:echo "<script type=\"text/javascript\">window.location.href=\"page.asp\"</script>"; Why that? Using header() is faster, and works with JS off.To give a concrete example for the topic starter:<?phpheader('Location: page.php');?> Link to comment Share on other sites More sharing options...
Ingolme Posted November 23, 2007 Share Posted November 23, 2007 Why that? Using header() is faster, and works with JS off.To give a concrete example for the topic starter:<?phpheader('Location: page.php');?> Be he wrote this:since you can't have two Headers in the same page and i can't have the redirect code in the default.phpSo I was supposing he couldn't use the header() function. Link to comment Share on other sites More sharing options...
boen_robot Posted November 23, 2007 Share Posted November 23, 2007 Be he wrote this:So I was supposing he couldn't use the header() function.Oh... well, if that was the case, there's always <meta/> redirects. They are certainly not faster, but they work with JS off too. Link to comment Share on other sites More sharing options...
Ingolme Posted November 23, 2007 Share Posted November 23, 2007 The problem with that is that it has to goes within the <head> tags. He said that those were the only examples he could find. Link to comment Share on other sites More sharing options...
zppblood Posted November 23, 2007 Share Posted November 23, 2007 Make sure that you use header() before you output anything. There are two headers you can use, Location and Refresh.header('Location: http://www.somepage.com/index2.html');exit; // Make sure to have this after header Location, otherwise the code will continue to runheader('Refresh: 10; url=http://www.somepage.com/index2.html'); // This will redirect the user to another page with 10 seconds after page loaded. Link to comment Share on other sites More sharing options...
Synook Posted November 24, 2007 Share Posted November 24, 2007 If you have to put the redirect function after some echoed text you can always buffer the output - read more at http://au2.php.net/manual/en/function.ob-start.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.