API Documentation

zferral API


Introduction

Single sign-off of affiliate

To enable a user to logout from both your website and the zferral Affiliate Panel, please complete the following steps:

  1. 1. Change the variables in lines 1 & 9 to match the variables set in your website
  2. 2. Copy the code (with your own changes)
  3. 3. Paste the code in the page which is shown after a successful log out from 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 OUT 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/logout.xml?remote_id='.$remote_id.'&timestamp='.$timestamp.'&t='.$t.'&i='.$i
    .'" style="border: none; display: none" alt=""/>';