Forum Moderators: coopster

Message Too Old, No Replies

Affiliate redirects

How to do it and where to put the code

         

zoltek

6:04 am on Feb 11, 2005 (gmt 0)

10+ Year Member



I've just recently been accepted into some affiliate programs and I'm looking to make it so that when a member of my site posts a link (in a phpbb forum, if that matters) to a particular product, the link "is changed" such that it now includes the affiliate referral code.

For example,

A member posts a link to a product...

[site.com...]

or some variation of the above, where XXXXX refers to that particular item's product ID.

I would like the outgoing link to be changed to the affiliate link, with that particular product ID inserted into the generic affiliate link.

I guess my problem boils down to a few points..

1) Extracting the product ID from the originally posted link.
2) Inserting that number into the affiliate link,
3) Redirecting/Replacing the original link with the now-updated affiliate link.

I'm pretty sure this is possible, as I have seen it done...but I have limited experience with PHP, and frankly, wouldn't even know where to include that particular code.

Any help would be greatly appreciated.

-Z

hakre

10:12 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



please read the tos of your affiliate programs that you're allowed to do so.

anyway, you should some more informatione what kind of forum you're using, because integrating such a routine into a forum is highly bound on the forum itself.

-hakre

zoltek

10:37 am on Feb 11, 2005 (gmt 0)

10+ Year Member



hi hakre,

Thanks for responding.

It is, indeed, all right with the affiliate programs. I've read the tos, as well as talked directly with them. I'm just trying to save myself the trouble of manually updating links one by one. Basically, a member finds a good deal on a product and posts the link. If I'm an affiliate for that particular merchant, then I edit the posted link such that it includes the referral code for that merchant.

As for what type of forum...

It's a phpbb forum. I have made no drastic changes to the default phpbb setup. My guess is that most of the changes will be made in viewtopic.php, but I have no idea if I'm right.

If you need any additional information, let me know.

zoltek

11:02 am on Feb 11, 2005 (gmt 0)

10+ Year Member



So in doing some more research, I realized the question I am asking has much too big of a scope, so in hopes of clearing things up, I'll think smaller and map things out in baby steps. If you guys could help out with any step, that would be fantastic. Here is what I think I need to do to get this working:

1) "Scan" the posts in the forums to find and isolate any links being posted (similar to how words are censored, I believe)

2) Parse the link to isolate the host (i.e. isolate 'store' out of [store.com...] I think I know how to do this with split() and/or explode().

3) Compare the parsed host with a list of the merchants I am affiliated to.

4) If it is an affiliate, then parse the XXXXXX portion out of the original posted link, and place it into a generic affiliate link.

5) Replace/Redirect the original posted link to my affiliate link

Hopefully that helped to explain what I'm trying to do.

jatar_k

6:04 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld zoltek,

you need an exit script

all links go to a single script that takes the actual url as a parameter. That script can then do the comparison you are talking about.

villan

6:13 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Looks like you have it all sorted out. You can probally keep it efficient by placing your replace code in whatever function the forum uses to parse links (if it is bbcode or something similar).

As for the replacing, do something like:


$affiliate1 = array("http://store1.com/","www.http://store1.com/");
$link = str_replace($affiliate1,"http://store1.com/XXXXX/",$link);

You can easily add more affiates etc, just make sure to watch for www. and non-www. links, or whatever subdomains/formatting the sites might use.

zoltek

11:17 am on Feb 12, 2005 (gmt 0)

10+ Year Member



Wow! Thank you guys for your help. I feel like I'm that much closer to understanding the solution.

So (in reference to my pseudo-checklist above) this is where I think I'm at...

1) "Scan" the posts in the forums to find and isolate any links being posted (similar to how words are censored, I believe)

So I still don't know how to do this, but the more I think about it, the more I realize this might be a question better asked in a phpbb-specific forum...in order to figure out how to "scan" posts(my guess, is the Word Censor scripts will provide a clue) and, more importantly, in which .php file to include this code in.

2) Parse the link to isolate the host (i.e. isolate 'store' out of [store.com...] I think I know how to do this with split() and/or explode().

Yep. I know how to do this. Thanks guys.

3) Compare the parsed host with a list of the merchants I am affiliated to.

I'm not sure how to do this. Can I store a list of affiliates as an array and cycle through that array comparing my parsed host to the affiliate names?

4) If it is an affiliate, then parse the XXXXXX portion out of the original posted link, and place it into a generic affiliate link.

Because of you guys, I know how to do this. Thanks!

5) Replace/Redirect the original posted link to my affiliate link

I'm not sure if I know how to do this. The uncertainty lies in whether I have to make an "exit script", as jatar advised, or if the steps I take in 4 (see above) will simply alter the original link, such that no redirection is needed.

Thanks again for the help, and I apologize for the "baby-steps" manner in which I am working through this. It's just that I'm so new to PHP, that this is the only way I can make my mind understand it all.

hakre

3:14 pm on Feb 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



for phpbb i've already tuned the bbcode parser to modify links on-the-fly. i've used that for creating an anomyzed redirection so the forum is keept more secure. anyway the same mechanism can be used for your problem. phpbb is quite a good board for such hacks and i hope version 3 will be even better then. but before hacking your board, ensure that you've got the latest version. there were some security issues on the run in the past and the hack has to be done by hand each time after updating the board.

zoltek

9:37 pm on Feb 12, 2005 (gmt 0)

10+ Year Member



Do you know which of the .php files has that BB parser code?

hakre

11:38 am on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if i remember correctly there is a file named bbcode.php in the inc or modules dir. this is handling it. i would start there and creating an additionall class you only need to drop in there. this will make it much more easy.