Page Redirection Problem (and hello)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
invisible A
Forum Newbie
Posts: 3
Joined: Fri Jan 23, 2004 11:34 am

Page Redirection Problem (and hello)

Post by invisible A »

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
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

invisible A,

well what you need to do is clear the header cache() uhm im not sure what the function name is but you can look it up in php manual. call it before calling the header() that probably should do the trick

Kendall
invisible A
Forum Newbie
Posts: 3
Joined: Fri Jan 23, 2004 11:34 am

Post by invisible A »

Done that already (I think) (but thank you)

In the end I think I'll go with using a simple Javascript redirected in the code, triggered when I get a reply from the databases.

I'm still interested in any other suggestions
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

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.

Code: Select all

<meta http-equiv="refresh" content="3; url=somepage.php">
The content=3 is the amount of time in seconds and the somepage.php is where you want to send them.
invisible A
Forum Newbie
Posts: 3
Joined: Fri Jan 23, 2004 11:34 am

Post by invisible A »

Does that have to go in head of the document?

(cheers by the way)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

you can yous javascript

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;
that will end up going in the bottom of the script after everything else has finished running

hope this helps
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

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.

Code: Select all

<meta http-equiv="refresh" content="3; url=somepage.php">
The content=3 is the amount of time in seconds and the somepage.php is where you want to send them.

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...
Post Reply