Forum Moderators: coopster

Message Too Old, No Replies

PHP Redirect Based On Query Variable

redirect based on php query

         

npimpfellow

5:08 am on Mar 10, 2009 (gmt 0)

10+ Year Member



Here is what I'm trying to do

I have an online store and I want to redirect certain items when they are sent to checkout

the link looks like this

order.php?ipa=11

I want to have ipa=11 redirect to http://www.example.com
ipa=12 redirect to http://www.example.com

all other item number function normally

I found this code:

<?php
$var = $_SERVER['query_STRING'];
{
header("Location: http://www.example.com");
exit;
}
?>

I need it to say "if query string is equal to 11 then header location is www.example.com
if query string is 12 then redirect to www.example.com/nextpage.html
and so on
but if the query string is 13 then the page will function as it does now

I hope this is enough information to figure out my problem, thanks in advance for any help on this topic!

[edited by: eelixduppy at 5:13 am (utc) on Mar. 10, 2009]
[edit reason] switched to example.com [/edit]

Habtom

9:20 am on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
$ipa = addslashes($_REQUEST['ipa']);
if ($ipa == 11) {
header("Location: http://www.example.com");
exit;
} else if ($ipa == 12) {
header("Location: http://www.example.com/nextpage.html ");
exit;
}

g1smd

3:03 pm on Mar 10, 2009 (gmt 0)

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



That HEADER will give a 302 redirect. Your site will be much safer if you change that to a 301 redirect.

npimpfellow

5:53 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



Is this how I would make it a 301 redirect? or is there a better way?

<?php
$ipa = addslashes($_REQUEST['ipa']);
if ($ipa == 11) {
Header( "HTTP/1.1 301 Moved Permanently" );
header("Location: http://www.example.com");
exit;
} else if ($ipa == 12) {
Header( "HTTP/1.1 301 Moved Permanently" );
header("Location: http://www.example.com/nextpage.html ");
exit;
}
?>

npimpfellow

5:59 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



looks like it worked! thanks for the help guys, I really appreciate it!

npimpfellow

6:20 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



ok one more problem
I'm using this script to redirect certain items in my online store to my affiliate partners.
The problem is that even with the redirect the item is getting added to the shopping cart!
I need to stop the rest of the script in my order.php file from executing IF the item is one of the numbers above.
maybe a way to tell it once it reads the redirect script to ignore any other scripts on the page below that?

Anyway, if you need more info please let me know.