Afternoon all, I'm new here, so hello
I have a wee problem with a php project I'm doing, and wondered if you could help (i'm relatively new to php, four months or so, but I've been coding Java for years).
Anyhow....
I have an online application form. It consists of a series of HTML pages, which pass variable to a Controller page. The Controller page is a PHP page, and takes the passed variables, does stuff to them (adds them to the db, manipulates them etc etc), and generates a page telling the user what has happened (ie the following variables have added.....).
What I need now is for this Controller page to automatically "forward" the user to the next HTML page in the questionaire.
I've tried to use the header("Location: http://www.google.com"); snippet, but this doesn't work, and I suspect this is because the Controller uses echo statements before it terminates.
To re-iterate the Controller is a big SWITCH statements, and each internal bit looks something like
case X:
output passed variables to the screen;
manipulate the variables;
stick them in the database;
and then forward to the next HTML page;
(and obviously break;)
If anyone can help, I'd be very greatful
Page Redirection Problem (and hello)
Moderator: General Moderators
-
invisible A
- Forum Newbie
- Posts: 3
- Joined: Fri Jan 23, 2004 11:34 am
-
invisible A
- Forum Newbie
- Posts: 3
- Joined: Fri Jan 23, 2004 11:34 am
If you want to display text on that page then header() is not the way to go. Headers forward the user immediately so they won't get enough time to read what you echo'd out. I would suggest that you use a Meta Refresh.
The content=3 is the amount of time in seconds and the somepage.php is where you want to send them.
Code: Select all
<meta http-equiv="refresh" content="3; url=somepage.php">-
invisible A
- Forum Newbie
- Posts: 3
- Joined: Fri Jan 23, 2004 11:34 am
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
you can yous javascript
that will end up going in the bottom of the script after everything else has finished running
hope this helps
Code: Select all
echo <<< EOT
<script type="text/javascript">
var goto = "index.php";//where you want to go
if(document.images)
{
window.location.replace(goto);
}
else
{
window.location = goto;
}
</script>
EOT;hope this helps
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
DuFF wrote:If you want to display text on that page then header() is not the way to go. Headers forward the user immediately so they won't get enough time to read what you echo'd out. I would suggest that you use a Meta Refresh.
The content=3 is the amount of time in seconds and the somepage.php is where you want to send them.Code: Select all
<meta http-equiv="refresh" content="3; url=somepage.php">
Yes, I would use DuFF's comment on the META tag for redirecting. And no, it doesn't have to be in the head of the document. Using Javascript relies on that the user has Javascript enabled, takes longer time to transfer the page, and the META tag is hella easier...