redirects in php
Moderator: General Moderators
redirects in php
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?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
This may be of interest:
viewtopic.php?t=1157
Mac
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 :
so it can all be in the same file - the form and the action perfomed on the form.
hope this is of some help
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
}hope this is of some help
- puckeye
- Forum Contributor
- Posts: 105
- Joined: Fri Dec 06, 2002 7:26 pm
- Location: Joliette, QC, CA
- Contact:
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...
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...
header() refresh/redirect with delay.
header() refresh/re-direct without delay
Code: Select all
<?php header("refresh: 5; url=http://$SERVER_NAME/page.php"); ?>Code: Select all
<?php header("Location: http://$SERVER_NAME/page.php"); ?>