Forum Moderators: coopster

Message Too Old, No Replies

Oh, no, another "how do I" redirect question

         

neophyte

1:20 pm on May 9, 2005 (gmt 0)

10+ Year Member



I've seen a simular question asked before, but when I tried it I couldn't get it to work so I abandoned the idea.

Well, I'm trying it again, and I get the same problem:

Warning: Cannot modify header information - headers already sent by (output started at c:\apache\htdocs\danielik_php\guest\tmpq7r6cg84lk.php:7) in c:\apache\htdocs\danielik_php\guest\tmpq7r6cg84lk.php on line 18

Here's all that I want to do:

After a form test proves TRUE, then:
1. Redirect the user to a different page.

Here's the code snippet I'm using:

<?php
if ($formValid == TRUE) {
header ("Location: 'index.php'");
//take user to the guest page
exit;
}
?>

I've read that there can't be any spaces before the header call, so I haven't indented it as I usually do in an IF statement.

what am I doing wrong? Is there another way to redirect a user to another page after a conditional test while still using php?

Neophyte

Stormfx

5:24 am on May 10, 2005 (gmt 0)

10+ Year Member



If the actual very beginning of your script is:

<?php
if ($formValid == TRUE) {
header ("Location: 'index.php'");
//take user to the guest page
exit;
}
?>

Then there's no reason why you should be getting that error. Try moving the 'if...' line up to the same line with the opening tag. If you still get the error, reboot the server.

If by change you're including a file or something before that statement, or that file is included by another page, make sure that there's no white space or output functions being called prior to your if statement.

ramoneguru

1:18 am on May 11, 2005 (gmt 0)

10+ Year Member



What's that "exit;" there for again?

If your getting that error then also check to see that you don't have any echos or print statements in there (maybe for testing you outputted something to the screen and forgot to remove it)

And if it still doesn't work then try this:

1. Print the form and when someone clicks a button or whatever, redirect them to a "temp processing page"
2. At this page, put in that "valid form" check or whatever, then redirect them to the index.php page if it is valid or do something else if it isn't valid.

Not the most incredible solution but a quick fix so you can get other things done....
--Nick

Stormfx

4:18 pm on May 11, 2005 (gmt 0)

10+ Year Member



Calling header('Location...') does not stop the processing of the page and usually poses a slight delay. By calling exit after the header() call, it prevents any other code from getting executed or output being sent.