View Full Version : Looking for a way to insert affiliate codes into links
MadMax
2004-10-01, 12:30 PM
I need to find a method (as simple as possible) to script a page to add affiliate codes to links on the page by grabbing the affiliate code from the incoming URL. Basically the same thing our friendly sponsors use for FHGs and FH sites.
If I can get some direction I'm willing to do the work to learn what I need to.
Chop Smith
2004-10-01, 12:53 PM
Check your private messages.
Chop Smith
2004-10-01, 02:00 PM
MadMax, resend your reply. My private messages box was full.
Rorschach
2004-10-03, 05:37 AM
Assuming you're changing the links on a dynamically generated free hosted gallery, eg. you're changing the links on:
http://www.fhgdomain.com/fhg.php?id=cocksmoker
On fhg.php:
<?php
// Extract the affiliate id from the url
$affiliate_id = $_GET['id'];
// Insert the affiliate id into the sponsor code
$link_url = "http://www.sponsordomain.com/clickthrough.php?id=$id";
// Print the modified url
print "<a href=\"$link_url\">Click here to check out this fucking amazing sponsor</a>";
?>
Barron
2004-10-03, 02:13 PM
This is the first script I created. Its since been rewritten several times, but it will get you started with *static* FHG's. There is only basic error checking included. You can do more if you need to.
Put the template tag where your tour links are.
<a href="%%url%%">Click here for great sponsor</a>
Assumes FHG link:
http://www.fghdomain.com/index.php?id=affiliate&tour=membership_tour
Put the code in a file called index.php
Watch for line wrap.
<?php
// Gallery you want to show
$fhg_path='/path/to/fhg.html';
//
// Declare template tag
$tpl_tag="%%url%%";
//
// Default Gallery just in case
$default_gallery_path='/path/to/default/fhg.html';
//
// Starting building your link
$link_url="http://www.sponsordomain.com/clickthrough.php?";
//
// We need dummy value anyway so lets
// track hits to fhg galleries
$link_url .="fhg=1";
//
// Extract affiliate info from URI
// and rebuild for link
foreach ($HTTP_GET_VARS as $key=>$aff_info)
{
if ($aff_info)
{
$aff_info=addslashes($aff_info);
$link_url .="&".$key."=".$aff_info;
}
}
//
// Default tour
//
/**** DANGER WILL ROBINSON! ****/
// Change the tour variable to whatever variable
// clickthrough.php looks for
//
if (!$_GET['tour'])
{
$link_url .="&tour=mytour";
}
//
// Get contents of fhg.html
$fhg_gallery=@file($path);
//
// If fhg.html doesnt exist get default
if (!$fhg_gallery)
{
$fhg_gallery=@file($default_gallery_path);
}
//
// If default doesnt exist
// show the surfer something!
if (!$fhg_gallery)
{
// watch for line wrap
header("Location: $link_url");
header("Expires: Mon, 26 jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0
header("P3P: CP=NOI DSP CURa PSAa PSDa OUR STP COM NAV STA");
header("Pragma: no-cache");
die();
}
//
// Do what we came here for.
// Replace the template tag
// and send gallery to browser
//
foreach ($fhg_gallery as $key=>$lines_in_fhg_gallery)
{
$lines_in_fhg_gallery=@str_replace($tpl_tag, $link_url, $lines_in_fhg_gallery);
echo "$lines_in_fhg_gallery";
}
?>
cykoe6
2004-10-15, 07:13 PM
Originally posted by Rorschach
Assuming you're changing the links on a dynamically generated free hosted gallery, eg. you're changing the links on:
http://www.fhgdomain.com/fhg.php?id=cocksmoker
On fhg.php:
<?php
// Extract the affiliate id from the url
$affiliate_id = $_GET['id'];
// Insert the affiliate id into the sponsor code
$link_url = "http://www.sponsordomain.com/clickthrough.php?id=$id";
// Print the modified url
print "<a href=\"$link_url\">Click here to check out this fucking amazing sponsor</a>";
?>
This is a very usefull script but I had to make a simple modifaction to get it to work. It should read as follows:
<?php
// Extract the affiliate id from the url
$affiliate_id = $_GET['id'];
// Insert the affiliate id into the sponsor code
$link_url = "http://www.sponsordomain.com/clickthrough.php?id=$affiliate_id";
// Print the modified url
print "<a href=\"$link_url\">$link_url</a>";
?>
Note the change on this line:
$link_url = "http://www.sponsordomain.com/clickthrough.php?id=$affiliate_id ";
Also if you want to use this script to insert codes into links from a form (so a reseller can insert his code and then have his ID insterted into all of your links, you can use the following:
<?php
// Extract the affiliate id from the url
$affiliate_id = $_POST['id'];
// Insert the affiliate id into the sponsor code
$link_url = "http://www.sponsordomain.com/clickthrough.php?id=$affiliate_id";
// Print the modified url
print "<a href=\"$link_url\">$link_url</a>";
?>
I hope this helps.
This script can also serve as the basis for a POTD script using iframes.
Rorschach
2004-10-17, 12:14 AM
Sorry about that, I just whacked it out and didn't test it before I posted. :)
MadMax
2004-10-18, 10:25 PM
Hey, no problem, and thanks for the help. Seems there are more ways of doing that then I thought |rasta|
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.