Page 1 of 1
Redirect function?
Posted: Mon Mar 22, 2004 6:54 pm
by jameso
Is there a function in PHP that will redirect, say, when I'm doing with code.
I know in ASP you can have something like
Code: Select all
<% Response.Redirect("URL_HERE") %>
but I don't know in PHP how to do this sort of thing.
Any ideas anyone?
I was maybe thinking use JavaScript with the window.location function or somehow using a META Refresh.
Posted: Mon Mar 22, 2004 7:04 pm
by markl999
header("Location: /foo.php");
exit;
The header must come before any output though, ie only useful if you're not 'sending anything to the user'. You can use
output buffering but best not to go there

before anything?
Posted: Mon Mar 22, 2004 9:14 pm
by jameso
so that function must precede all other code?
I want to send a user to a location after filling out a form, but I have other things, like headers and such, in include files, that have to be loaded.
Will this still work? (I'm trying it out right now but I want to know what problems can arise and how I can correct them)
Thanks!
Posted: Mon Mar 22, 2004 9:17 pm
by markl999
It wil work as long as you don't send output. Output is basically anything that gets sent to the browser/client, such as html and even whitespace (outside of php tags).
So you can do show form->post form->process form->redirect
But if you want to do show form->post form->process form->display something to the user->redirect, then the header won't work (unless you use the previously mentioned output buffering), in this case using a meta-refresh is usually better.
Posted: Mon Mar 22, 2004 9:18 pm
by Illusionist
Posted: Tue Mar 23, 2004 1:00 am
by rajivkrishnang
no echo should work before redirection; thts all;
u can have any no of redirection
thanks
Posted: Tue Mar 23, 2004 1:22 am
by jameso
Thanks guys.
I think I get it.