Page 1 of 1
redirects in php
Posted: Thu Jan 23, 2003 5:20 am
by rk
I am a coldfusion developer and in CF there is the nice <cflocation url=""> tag which lets you redirect anywhere from the page to another location. Great for refreshing pages and so after performing a form action. But in PHP I only came across the function to send a http header, before any code is executed. Is it possible to make redirects after for example a query is executed?
Posted: Thu Jan 23, 2003 5:46 am
by twigletmac
You can use the
header() function to redirect the page before anything is output to the browser - so it can be used after some code has been executed.
This may be of interest:
viewtopic.php?t=1157
Mac
Posted: Thu Jan 23, 2003 8:00 am
by elipollak
I had to do some coldfusion work for a while ...
ugh ... it made me appreciate php even more than I already did.
Anyway, in php, if you have a form with submit button name = "send", then u can have in your php script :
Code: Select all
if ($send) {
// do stuff with info you got
// then
print " ... successful or woteva";
print"<a href=........>click here to go to some other page</a>";
}
else {
// print out the form itself :
print "<form action="" method="post">
// note action="" says post back to this page
//........ rest of form
}
so it can all be in the same file - the form and the action perfomed on the form.
hope this is of some help
Posted: Fri Jan 24, 2003 3:58 pm
by puckeye
You can always use the META TAG refresh to redirect to another page...
But I think twigletmac is right about using header().
I use this all the time to prevent users from reloading the form processing page. If your form doesn't check out youcan output some warnings and reprint the form with valid fields already filled otherwise you can write a header ("Location:someURL") function...
Posted: Fri Jan 24, 2003 6:38 pm
by Kriek
header() refresh/redirect with delay.
Code: Select all
<?php header("refresh: 5; url=http://$SERVER_NAME/page.php"); ?>
header() refresh/re-direct without delay
Code: Select all
<?php header("Location: http://$SERVER_NAME/page.php"); ?>