I am working on PHP code for automatically redirecting a URL to an affiliate URL based on words in the URL.
This is the code I am using:
if (stripos($mylink, "amazon.in") > 0) {
if (strpos($mylink, "?") > 0) {
$tmp = $mylink."&affiliate_id";
} else {
$tmp = $mylink."?affiliate_id";
}
$loc = "Location:".$tmp;
header($loc);
exit();
}
But the problem is that when the Amazon URL is like: http://www.amazon.in/English-Movies-TV-Shows/b/ref=sa_menu_movies_all_hindi?ie=UTF8&node=4068584031
it adds the affiliate id like this: ie=UTF8&affiliate_id
(it automatically removes the node and its value) but I want it to be like: ie=UTF8&node=4068584031&affiliate_id
.
This means that I need to add &affiliate_id
at the end of the URL every time if it is an Amazon link.
Actually I just want to achieve the following simple thing: if the URL doesn't have any ?
s, I need to place ?affiliateid
and if the URL has a ?
, I just need to append &affiliateid
at the end.
Can you suggest the very simple method for implementing what I require?