API Documentation
zferral API
Introduction
Single sign-on of affiliate
To enable a user to seamlessly login to both your website and the zferral Affiliate Panel, please complete the following steps:
- 1. Change the variables in lines 1 & 9-12 to match the variables set in your website
- 2. Copy the code (with your own variables)
- 3. Paste the code in the page that follows a successful authentication (user login) on your website.
Mcrypt extension is required!
Code to be pasted:
require_once 'zferralApi/ZferralLoader.php'; // HERE SET PATH TO ZferralLoader.php SCRIPT
$c = new ZferralConnector($apikey, $subdomain);
$token = $c->getAuthToken();
$t = urlencode(md5($token));
$timestamp = time();
$signature = urlencode(md5($apikey.$subdomain.$timestamp));
$i = 0;
$remote_id = USER_ID_FROM_YOUR_SYSTEM; // HERE SET ID OF LOGGED USER
$first_name = FIRST_NAME; // HERE SET FIRST NAME OF LOGGED USER
$last_name = LAST_NAME; // HERE SET LAST NAME OF LOGGED USER
$email = EMAIL; // HERE SET EMAIL OF LOGGED USER
try {
if (function_exists('mcrypt_encrypt')) {
$cipher = MCRYPT_CAST_256; // DEFAULT CIPHER (change value to MCRYPT_CAST_128 if you have chosen
// this one in API settings: https://zferral.com/profile/api)
$mode = MCRYPT_MODE_CBC;
$key = substr(md5($token.$apikey.$subdomain.$timestamp), 0, mcrypt_get_key_size($cipher, $mode));
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_RAND);
$i = urlencode(base64_encode($iv));
$remote_id = urlencode(base64_encode(mcrypt_encrypt($cipher, $key, $remote_id, $mode, $iv)));
} else throw new Exception('mcrypt extension is required.');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
echo '<img src="http://'.$subdomain.'.zferral.com/api/'.$signature.'/affiliate/login.xml?remote_id='.$remote_id.'×tamp='.$timestamp.'&t='.$t.'&i='.$i
.'&first_name='.urlencode($first_name).'&last_name='.urlencode($last_name).'&email='.urlencode($email).'" style="border: none; display: none" alt=""/>';
Login