-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaff.php
64 lines (52 loc) · 1.83 KB
/
aff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Affiliate Cookie Tracking + Redirection Handler
*
* @package WHMCS
* @author WHMCS Limited <[email protected]>
* @copyright Copyright (c) WHMCS Limited 2005-2018
* @license https://www.whmcs.com/license/ WHMCS Eula
* @version $Id$
* @link https://www.whmcs.com/
*/
use WHMCS\Affiliate\Referrer;
use WHMCS\Carbon;
use WHMCS\Cookie;
define("CLIENTAREA",true);
require("init.php");
// if affiliate id is present, update visitor count & set cookie
if ($aff = $whmcs->get_req_var('aff')) {
update_query("tblaffiliates",array("visitors"=>"+1"),array("id"=>$aff));
Cookie::set('AffiliateID',$aff,'3m');
$referrer = trim($_SERVER['HTTP_REFERER']);
Referrer::firstOrCreate([
'affiliate_id' => $aff,
'referrer' => $referrer,
])->hits()->create([
'affiliate_id' => $aff,
'created_at' => Carbon::now()->toDateTimeString(),
]);
}
/**
* Executes when a user has clicked an affiliate referral link.
*
* @param int $affiliateId The unique id of the affiliate that the link belongs to
*/
run_hook("AffiliateClickthru", array(
'affiliateId' => $aff,
));
// if product id passed in, redirect to order form
if ($pid = $whmcs->get_req_var('pid')) redir("a=add&pid=".(int)$pid,"cart.php");
// if product group id passed in, redirect to product group
if ($gid = $whmcs->get_req_var('gid')) redir("gid=".(int)$gid,"cart.php");
// if register = true, redirect to registration form
if ($whmcs->get_req_var('register')) redir("","register.php");
// if gocart = true, redirect to cart with request params
if ($whmcs->get_req_var('gocart')) {
$reqvars = '';
foreach ($_GET AS $k=>$v) $reqvars .= $k.'='.urlencode($v).'&';
redir($reqvars,"cart.php");
}
// perform redirect
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$whmcs->get_config('Domain'),true,301);