Need Urgent Help In code based on redirecting based on words

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saharsh
Forum Newbie
Posts: 4
Joined: Mon Jun 16, 2014 3:11 pm

Need Urgent Help In code based on redirecting based on words

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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"
(#10850)
saharsh
Forum Newbie
Posts: 4
Joined: Mon Jun 16, 2014 3:11 pm

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

Post 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.
saharsh
Forum Newbie
Posts: 4
Joined: Mon Jun 16, 2014 3:11 pm

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

Post by saharsh »

Please help me!!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

Is this what you're trying to do?

Code: Select all

if (stripos($mylink, '?') !== false) { $mylink .= '&affiliateid=abc'; } else { $mylink .= '?affiliateid=abc'; }
saharsh
Forum Newbie
Posts: 4
Joined: Mon Jun 16, 2014 3:11 pm

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

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

That's an entirely separate issue, then. Where are you getting $mylink from?
Post Reply