Dear All,
I am a JSP programmer, trying to get my first PHP app running.
How do I redirect from one php to another. Or, whats the equivalent of Request.Redirect ? I tried Location("index.php") and it gave me the usual "Headers have already been sent" error.
Regards,
Kecheri
Answers
Add Answerbe careful there's no any othere output before the location.
Alternative is to use Java Script
This is what I got from google.
";
print " self.location='mynewpage.html';";
print "";
?>
google and doc
It simple but there is one condition to it the file/page that would redirect the user should not have another tag, code etc before the redirect code, simply put this is what you need to do.
That's it!
Sorry the code didn't show but here is what you need to do.
- create a new empty php file.
- type the open and close php tag
- in between the tags write
"header( 'Location: http://www.yoursite.com/new_page.html' ) ;"
- without the quotation marks of course.
window.location=your url.
There are 3 ways in order to redirect to another page:
1) send a "Location"-header in response (make sure that no content has been send before you are trying to send any header in PHP - this is the most preferred way;
2) echo some javascript like this: echo 'window.location = 'google.com';';
3) Use a equivalent to the 'Location' header inside your ;
Sorry, seems like ostatic doesn't autoescape my html-parts - it just stripes them out.
So, in no. 2 I mean <script type="text/javascript">window.location = 'google.com';</script>
And in no. 3 - a META-tag, equivalent to the 'Location'
By an anonymous user on Oct. 07, 2008
е
USE JS
Use javascript window.location
Have you got it?
you could use javascript to do that
google~
Share your knowledge