API Documentation
zferral API
Introduction
Single sign-on of affiliate (with login details from zferral)
To enable a user to seamlessly login to both your website and the zferral Affiliate Panel (with login details from zferral), please complete the following steps:
- 1. Change the variables in lines 1 & 9-10 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;
$login = LOGIN; // HERE PASS IN USER LOGIN
$password = PASSWORD; // HERE PASS IN USER PASSWORD
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));
$pass_encrypt_key = substr(md5($apikey), 0, mcrypt_get_key_size($cipher, $mode));
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_RAND);
$encPass = urlencode(base64_encode(mcrypt_encrypt($cipher, $pass_encrypt_key, $password, $mode, $iv)));
$iv = urlencode(base64_encode($iv));
} else throw new Exception('mcrypt extension is required.');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
$auth = $c->zfAuth('affiliate', array('username' => $login, 'password' => $encPass, 'iv' => $iv));
if (intval($auth) !== 0) {
try {
if (function_exists('mcrypt_encrypt')) {
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_RAND);
$i = urlencode(base64_encode($iv));
$login = urlencode(base64_encode(mcrypt_encrypt($cipher, $key, $login, $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?login='.$login.'×tamp='.$timestamp.'&t='.$t.'&i='.$i.
'" style="border: none; display: none" alt=""/>';
}

Login