Forum Moderators: coopster
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
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.
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.
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.
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.