The following is a full code example. Change values accordingly for your own setup. You should change the GET variable if you have renamed it and you should make the cookie name more
obscure for security. Remember to use the same cookie var in the
commission calls. It is also a good idea
to sanitize the affiliate code, for example, if your affiliate codes are alphanumeric, check the value is alphanumeric.
If you get the code directly from the
product page in your Maian Affiliate admin area, the key, product ID and a more obscure cookie key are
completed for you.
<?php
// Check for affiliate code
if (isset($_GET['maff'])) {
// Set cookie if not already set
if (!isset($_COOKIE['msw_aff_2018151810_code'])) {
setcookie('msw_aff_2018151810_code', $_GET['maff'], time() + 60 * 60 * 24 * 180);
}
// Prepare array..
$data = array(
'apikey' => 'YOUR API KEY HERE..',
'affiliate' => $_GET['maff'],
'referrer' => array(
'url' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''),
'ip' => (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''),
'product' => 'PRODUCT ID HERE..'
)
);
// Send to API..
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.path-to-your-maian-affiliate-setup.com/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$r = json_decode(curl_exec($ch), true);
curl_close($ch);
// Do something with response..
if (isset($r['status'])) {
switch($r['status']) {
case 'error':
// Handle error message..
break;
case 'ok':
// Reload page
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
header("Location: " . $url);
exit;
break;
}
} else {
// Check logs folder in Maian Affiliates, something went wrong
}
}
?>
You can copy and paste the above code if you need to. You should change the api key and product ID values and make sure the CURLOPT_URL path
is correct. If the $url value isn't correct for the redirect, enter your page url manually. Example:
$url = 'https://www.example.com/site/';