Forum Moderators: coopster

Message Too Old, No Replies

Using If/else to Redirect to Different Headers

         

wsamoht

5:44 pm on Aug 25, 2008 (gmt 0)

10+ Year Member



if ($Register = 'Yes') {
header( "Location: [test.com...] );
}
else {
header( "Location: [test...] false );

This if statement is within the mail function. If you want the rest of the code let me know.

My goal is to redirect a guest to one page if they selected something on the form whose value is Yes.

If they didn't select it then they will be directed to another page.

My script runs but it always redirects to the first header.

cameraman

6:50 pm on Aug 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That needs to be:
if ($Register == 'Yes') {

wsamoht

7:16 pm on Aug 25, 2008 (gmt 0)

10+ Year Member



Thank you. That works!

g1smd

11:41 pm on Aug 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That's also probably a 302 redirect.

You probably will want to change it to be a 301 redirect.

wsamoht

12:11 am on Aug 26, 2008 (gmt 0)

10+ Year Member



i am new to PHP and server side scripting. what do you mean by 301 and 302 redirect?

g1smd

12:31 am on Aug 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When you request a URL from a server, the response incudes a code in the HTTP Header.

The HTTP Header is sent out before even the very first HTML tag on the page.

That number is 200 if the page is found, and 404 if it is not found.

If the page has moved, it will be 301 or 302. There are major problems with 302 so you will almost always want to use 301.

You'll also come across 304, 307, 401, 403, and 500 on your travels. There are many previous threads with details.

The Live HTTP Headers extension for Mozilla Firefox and Mozilla Seamonkey can show you exactly what is going on.

cameraman

12:46 am on Aug 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are the major problems with 302?
It seems to me that 303 would be more appropriate. Hard to say for sure but it looks like the script is making a decision as to whether the visitor is initiating or finishing up payment, so 301 is unlikely to be correct, and according to RFC2616:
Many pre-HTTP/1.1 user agents do not understand the 303 status. When interoperability with such clients is a concern, the 302 status code may be used instead, since most user agents react to a 302 response as described here for 303.

so a 302 would be about the best...
What am I missing?