Page 1 of 1

Need Urgent Help In code based on redirecting based on words

Posted: Mon Jun 16, 2014 3:19 pm
by saharsh
Hi ,
I need a urgent Help regarding Php code which is based on automatic redirecting a url to affiliate url based on words in url.
this is the code i am using:

Code: Select all

if( stripos($mylink,"amazon.in")>0)
{ if(strpos($mylink,"?")>0)
$tmp = $mylink.str_replace("?","&","?affiliate_id");
 else
 $tmp = $mylink."?affiliate_id";
 $loc = "Location:".$tmp;
 header($loc); 
 exit();
}
But the problem is that when the amzon url is like :-
http://www.amazon.in/English-Movies-TV- ... 4068584031

it adds the affiliate id like this:-
http://www.amazon.in/English-Movies-TV- ... filiate_id

but i want it to be like :-
http://www.amazon.in/English-Movies-TV- ... filiate_id

Means i need to add "&affiliate_id" athe end of url everytime if it is of amazon.
Please refer my website :http://www.bestonlinedeals.co.in

Re: Need Urgent Help In code based on redirecting based on w

Posted: Mon Jun 16, 2014 4:02 pm
by Christopher
if it is always "?ie=UTF8&affiliate_id" and you want "?ie=UTF8&node=4068584031&affiliate_id" then you could just replace "affiliate_id" with "node=$node&affiliate_id".

PS - in your code above, the line:

$tmp = $mylink.str_replace("?","&","?affiliate_id");

is the same as:

$tmp = $mylink."&affiliate_id"

Re: Need Urgent Help In code based on redirecting based on w

Posted: Mon Jun 16, 2014 4:10 pm
by saharsh
Thanks for reply
But this node value keep on changing.actually i just want to achieve one simple thing if url doesnt have any "?"i need to place "?affiliateid" and if url has ? i just need to append "&affiliateid" at the end .
can u suggest the very simple method for this thing.

Re: Need Urgent Help In code based on redirecting based on w

Posted: Tue Jun 17, 2014 2:26 pm
by saharsh
Please help me!!

Re: Need Urgent Help In code based on redirecting based on w

Posted: Tue Jun 17, 2014 5:08 pm
by Celauran
Is this what you're trying to do?

Code: Select all

if (stripos($mylink, '?') !== false) { $mylink .= '&affiliateid=abc'; } else { $mylink .= '?affiliateid=abc'; }

Re: Need Urgent Help In code based on redirecting based on w

Posted: Tue Jun 17, 2014 6:11 pm
by saharsh
Problem is that the mylink i am getting itself doesnt contain the node i need someone to help me figure out why it is happening like that can some help me through gtalk?

Re: Need Urgent Help In code based on redirecting based on w

Posted: Tue Jun 17, 2014 6:57 pm
by Celauran
That's an entirely separate issue, then. Where are you getting $mylink from?