passing variables to outgoing links through PHP redirect

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
php246
Forum Newbie
Posts: 3
Joined: Sat Apr 28, 2007 12:13 am

passing variables to outgoing links through PHP redirect

Post 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.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post 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
php246
Forum Newbie
Posts: 3
Joined: Sat Apr 28, 2007 12:13 am

Post by php246 »

Hi,

Thanks.

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

How do we pass the variable?

Thanks.
Post Reply