View Full Version : HOWTO: redirect affiliate links to cart instead of homepage
freedombi
06-11-08, 11:13 PM
The default behavior of aff.php is to set a cookie with the affiliate id, and then send the user to the homepage. This prevents being able to link to a specific product or product group, and may be a bit confusing. Below, I have an aff.php which, in addition to aff, also accepts gid or pid in the URL, and redirects to the appropriate group or product, respectively. gid takes precedence over pid.
aff.php:
<?php
define("CLIENTAREA",true);
include("dbconnect.php");
include("includes/functions.php");
if (isset($aff)) {
update_query("tblaffiliates",array("visitors"=>"+1"),array("id"=>$aff));
setcookie("WHMCSAffiliateID", $aff, time()+90*24*60*60);
}
$params = '';
// redirect to product group
if (isset($_GET['gid'])) {
$gid = (int)$_GET['gid'];
if ($gid > 0) {
$params = '?gid=' . $gid;
}
}
// redirect to product
elseif (isset($_GET['pid'])) {
$pid = (int)$_GET['pid'];
if ($pid > 0) {
$params = '?a=add&pid=' . $pid;
}
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $CONFIG['SystemURL'] . '/cart.php' . $params);
?>
I know its been 3 weeks since this was posted (and thank you very much freedombi for sharing it) but....
Has anyone had any success in using this? and to what extent?
Reason im asking is that i now have the need for something like this, ideally a direct group link which would contain the group id, affiliate id and promotion code, basically something like:
http://www.mydomain.com/cart.php?aff=001&promocode=coupon&gid=0000000003
Any suggestions are welcome, cheers.
Can you provide an example of how you used this, please?
The default behavior of aff.php is to set a cookie with the affiliate id, and then send the user to the homepage. This prevents being able to link to a specific product or product group, and may be a bit confusing. Below, I have an aff.php which, in addition to aff, also accepts gid or pid in the URL, and redirects to the appropriate group or product, respectively. gid takes precedence over pid.
aff.php:
<?php
define("CLIENTAREA",true);
include("dbconnect.php");
include("includes/functions.php");
if (isset($aff)) {
update_query("tblaffiliates",array("visitors"=>"+1"),array("id"=>$aff));
setcookie("WHMCSAffiliateID", $aff, time()+90*24*60*60);
}
$params = '';
// redirect to product group
if (isset($_GET['gid'])) {
$gid = (int)$_GET['gid'];
if ($gid > 0) {
$params = '?gid=' . $gid;
}
}
// redirect to product
elseif (isset($_GET['pid'])) {
$pid = (int)$_GET['pid'];
if ($pid > 0) {
$params = '?a=add&pid=' . $pid;
}
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $CONFIG['SystemURL'] . '/cart.php' . $params);
?>
edvan.com.br
09-17-09, 01:03 PM
<?php
define("CLIENTAREA",true);
include("dbconnect.php");
include("includes/functions.php");
if (isset($aff)) {
update_query("tblaffiliates",array("visitors"=>"+1"),array("id"=>$aff));
setcookie("WHMCSAffiliateID", $aff, time()+90*24*60*60);
}
$params = '';
// redirect to product group
if (isset($_GET['gid'])) {
$gid = (int)$_GET['gid'];
if ($gid > 0) {
$params = '?gid=' . $gid;
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $CONFIG['SystemURL'] . '/cart.php' . $params);
}
// redirect to product
elseif (isset($_GET['pid'])) {
$pid = (int)$_GET['pid'];
if ($pid > 0) {
$params = '?a=add&pid=' . $pid;
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $CONFIG['SystemURL'] . '/cart.php' . $params);
}
// redirect domain
else
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$CONFIG["Domain"]);
}
?>
This is exactly what I need as well, I installed mine at /panel/cart.php and I'd like to be able to assign a promo code and affiliate code to a certain link. How would I do that?
freedombi
09-23-09, 07:15 PM
I haven't really done much with coupons or promo codes, myself. The question is how does it register that you have a coupon? I'm guessing it's not passed in the URL. If it's stored as a cookie, then you would just set the cookie from within the script. If it's just submitted as part of a form on one page, then I don't know if it's possible.
How would I get the affiliate link to go to www.mydomain.com/panel/cart.php ?
freedombi
09-28-09, 05:28 PM
Either set SystemURL to www.mydomain.com/panel (in Configuration) or edit the script so it goes to that location.
Thanks that was easy, is there anything maybe negative to having it set to mydomain.com/panel/cart.php under Config, General, Domain:
Inetbiz
10-01-09, 04:19 PM
What would really be spiffy is some smarty logic that helps them build custom links. Much like CRE Loaded Cart Affiliate Manager build custom links. In that cart, the store admin can BUILD links, let the affiliate search for a product and display the custom affiliate link or show a list of available banners OR what I would like to see from idevaffiliate is a way whmcs admins could create text box banners like google.
So with that revised aff.php page what affiliate url do you set up in the banners area to give the correct redirection? to a group or promotion.
http://domainname.com/aff.php?aff=### then what ?????
thanks
ian
Inetbiz
10-12-09, 10:03 PM
When I read http://wiki.whmcs.com/Affiliates it inserts a smarty variable. How would your code work with this wiki article?
kennyjewels
10-22-09, 10:17 AM
Oh thanks if it really works because it s very helpful trick.
Joneiby Jimenez
09-04-12, 01:35 PM
Hello,
I need my WHMCS with the referral link will redirect you to register and have registered as referrals.
jaytheshop
11-06-12, 09:22 PM
How can I make an Affiliate Banner contain a Promo Code? When my affiliates copy our banners html and paste in on theirt website, it does not include any discount for the end customer... We want the affiliate banners to contain discount promo codes so the affiliate earns commission and the customer gets a discount..
I tried this but it does not add the discount code to the cart....
<a href="http://atmohost.com/[AffiliateLinkCode]/cart.php?promocode=migone"><img src="http://www.atmohost.com/templates/BlueHost/html/images/affbanners/atmo-affiliate1.jpg" width="200" height="300" border="0"></a><br>
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.