Forum Moderators: coopster

Message Too Old, No Replies

Redirects and Variables Help

Need some how to advice

         

pede6

3:01 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



If I want to do a PHP redirect and append a variable to the end of the destination URL, how do I do that?

I am sending visitors from my site to an external site through a redirect page on my site (redirect.php). When visitors come to my site, the 'id' parameter is set based on where they came from, and this is working properly. Redirect.php has the following code:

<?
$l = $_GET['l'];
$id = $_GET['id'];
$links = array();

$links['#*$!'] = 'http://www.example.com?id='.$_REQUEST['id'];

header('Location: '.$links[$l]);

exit();
?>

This sends my visitors to www.example.com, but does not correctly append the 'id' to the end of the URL. Is there a different way I should go about this?

Thanks,
Pede

[edited by: eelixduppy at 7:31 pm (utc) on Nov. 23, 2007]

jatar_k

5:24 pm on Nov 23, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld pede6,

what's going on there is a little confusing as most of it seems to have no point in that snippet, something like this should do

$id = $_GET['id'];
header('Location: http://www.example.com?id='.$id);

pede6

7:02 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



jatar,

Thank you for the reply and the welcome. Would the code you proposed only be applicable to 1 link? I have several links I would like to redirect in the same way with the id, so that was the reason for the array. I should have been more specific that my original post was an example that will apply to many links. If it will work for many links, that's great!

Thanks again for the assistance.

Pede

php4U

8:18 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



Have you tried $_POST or $_GET instead?

The way I understand it is that $_REQUEST could be a combination of any of those, and therefore may be quirky at times. Someone else may be able to clarify that, if that is not the case. Good luck