Passing URL parameters (GET variables) on a PHP redirect

0
677

This was something quite simple that shouldn’t have taken me as long as it did to figure out.

I had traffic going to one url: http://myserver.com/lander.php?source=google&campaign=no1&c1=foobar

I wanted to split the traffic to try two different conversion funnels. The thing was I needed to keep the source, campaign, c1 variables in the url and pass them through to the following landing page so they could be tracked correctly.

So I setup the two conversion funnels at:
lpa.php and lpb.php using the original as a template

Then I used the following code in lander.php to redirect the traffic to the new landing pages on a 50/50 split.


<?php
if (rand(0,1) == 0) {
$url = 'lpa.php';
} else {
$url = 'lpb.php';
}
header("Location: $url".'?'.$_SERVER['QUERY_STRING']);
?>

This is useful if you don’t want to change the URL at the traffic source and just split the traffic internally without messing up your logging.

The url paramaters that would normally be tracked with $_GET are passed via the $_SERVER[‘QUERY_STRING’] variable.

LEAVE A REPLY

Please enter your comment!
Please enter your name here