Page 1 of 1

passing variables to outgoing links through PHP redirect

Posted: Sat Apr 28, 2007 12:42 am
by php246
Hi,

We don't know how to pass variables through PHP redirect script to outgoing links. All pages within the site are HTML. Links are maintained in one PHP file called links.php

The outgoing link within HTML would look like this:

Code: Select all

http://www.oursite.com/links.php?m=link23
The code of links.php looks like this:

Code: Select all

<?

if ($_GET['m'] == "link23") {$link = "http://www.goout1.com";}
if ($_GET['m'] == "link24") {$link = "http://www.goout2.com";}

header("Location: $link");
?>
Problem is:

How do we pass variables from incoming traffic that while you browse our site look like:

Code: Select all

http://www.oursite.com/somepage.html?variable1=XY&variable2=XZ
What we would want to happen is to get variables inserted into our links.php so it looks like this:

Code: Select all

<?

if ($_GET['m'] == "link23") {$link = "http://www.goout1.com?variable1=XY&variable2=XZ ";}
if ($_GET['m'] == "link24") {$link = "http://www.goout2.com?variable1=XY&variable2=XZ ";}

header("Location: $link");
?>
Please note that a string after "?" can be one word only, simply anything.

We just tried to present what we want to achieve. In real life, we don’t care how it happens, as long as we can continue to maintain our outgoing links in one PHP file.

Many thanks.

Posted: Sat Apr 28, 2007 12:59 am
by mentor
Use $_SERVER["QUERY_STRING"] as below

Code: Select all

<? 

if ($_GET['m'] == "link23") {$link = "http://www.goout1.com";} 
if ($_GET['m'] == "link24") {$link = "http://www.goout2.com";} 

header("Location: {$link}?".$_SERVER["QUERY_STRING"]); 
?>
Also visit the manual for $_SERVER

Posted: Sat Apr 28, 2007 10:45 am
by php246
Hi,

Thanks.

It is not passing the variable. It passes "link23" in this example.

How do we pass the variable?

Thanks.