Jump to content

response.redirect in PHP


Vernersson

Recommended Posts

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

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

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

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.php
So I was supposing he couldn't use the header() function.
Link to comment
Share on other sites

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

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

Archived

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

×
×
  • Create New...