JavaScript Editor Ajax software     Free javascripts 



Main Page

{
// save the affiliate ID
$_SESSION[‘aff_id’] = $_REQUEST[‘aff_id’];
// obtain the URL with no affiliate ID
$clean_url = SITE_DOMAIN . remove_query_param($_SERVER[‘REQUEST_URI’], ‘aff_id’);
// 301 redirect to the new URL
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: ‘ . $clean_url);
}
Finally,
aff_test.php
checks whether there’s a session parameter named
aff_id
set. In case it is, your
user got to the page through an affiliate link, and you’ll need to take this into account when dealing with
this particular user. For the purposes of this simple exercise, you’re simply displaying the affiliate ID, or
(no affiliate)
in case the page was first loaded without an
aff_id
parameter.
// display affiliate details
echo ‘You got here through affiliate: ‘;
if (!isset($_SESSION[‘aff_id’]))
{
echo ‘(no affiliate)‘;
}
else
{
echo $_SESSION[‘aff_id’];
}
?>
It’s also worth analyzing what happens inside the
remove_query_param()
function from
url_utils
.inc.php
. The strategy you took for removing one query string parameter is to transform the existing
query string to an associative array, and then compose the associative array back to a query string, after
removing the
aff_id
element.
To keep the code cleaner, you have a separate function that transforms a query string to an associative
array. This function is named
parse_query_string()
, and receives as parameter a query string, such
as
a=1&aff_id=34&b=2
, and returns an associative array with these elements:
‘a’ => ‘1’
‘aff_id’ => ‘34’
‘b’ => ‘2’
The function starts by using
explode()
to split the query string on the
&
character:
// transforms a query string into an associative array
function parse_query_string($query_string)
{
// split the query string into individual name-value pairs
$items = explode(‘&‘, $query_string);
115
Chapter 5: Duplicate Content
c05.qxd:c05 10:41 115


JavaScript Editor Ajax software     Free javascripts