Custom Short URL and Affiliate Traffic Tracking System


  • Generate or get existing short URLs, with sequential or custom keyword
  • Get some statistics about your links: top clicked links, least clicked links, newest links
  • Output format: JSON, XML, or simple raw text
  • Authentify either with login/password or using a secure passwordless mechanism


You need to send parameters to either via GET or POST (remember to URL encode parameters if via GET). These parameters are:

  • A valid username / password pair, or your signature
  • The requested action"shorturl" (get short URL for a link), "expand" (get long URL of a shorturl), "url-stats" (get stats about one short URL), "stats" (get stats about your links) or "db-stats" (get global link and click count)
  • With action = "shorturl" :
    • the url to shorten
    • optional keyword and title for custom short URLs
    • output format: either "jsonp""json""xml" or "simple"
  • With action = "expand" :
    • the shorturl to expand (can be either ‘abc’ or ‘http://site/abc’)
    • output format: either "jsonp""json""xml" or "simple"
  • With action = "url-stats" :
    • the shorturl for which to get stats (can be either ‘abc’ or ‘http://site/abc’)
    • output format: either "jsonp""json" or "xml"
  • With action = "stats" :
    • the filter: either "top""bottom" , "rand" or "last"
    • the limit (maximum number of links to return)
    • output format: either "jsonp""json" or "xml"
  • With action = "db-stats" :
    • output format: either "jsonp""json" or "xml"

Sample requests

Example of a GET request with Javascript (using jQuery) to shorten a URL

var api_url  = 'http://sho.rt/AFFTRACKERS-api.php';
var response = $.get( api_url, {
    username: "your_username",
    password: "your_password",
    action:   "shorturl",
    format:   "json",
    url:      ""
    // callback function that will deal with the server response
    function( data) {
        // now do something with the data, for instance show new short URL:

Example of a POST request with PHP to expand a short URL

$username = 'your_username';
$password = 'your_password';
$api_url =  'http://sho.rt/AFFTRACKERS-api.php';

// Init the CURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, 0);            // No header in the result
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
curl_setopt($ch, CURLOPT_POST, 1);              // This is a POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, array(     // Data to POST
        'shorturl' => 'ozh',
        'format'   => 'json',
        'action'   => 'expand',
        'username' => $username,
        'password' => $password

// Fetch and return content
$data = curl_exec($ch);

// Do something with the result. Here, we echo the long URL
$data = json_decode( $data );
echo $data->longurl;

Sample returns

Sample return in JSON format for the shorturl action

  "url": {
    "keyword": "ozh",
    "url": "http:\/\/",
    "title": "Ozh RICHARD \u00ab",
    "date": "2014-10-24 16:01:39",
    "ip": ""
  "status": "success",
  "message": "http:\/\/ added to database",
  "title": "Ozh RICHARD \u00ab",
  "shorturl": "http:\/\/sho.rt\/1f",
  "statusCode": 200

Sample return in XML format for the expand action


Usage of the signature token

Use parameter signature in your API requests. Example:


Usage of a time limited signature token

You can create signature token valid for a short period only (one hour by default)

First, craft the time limited signature token:

$timestamp = time();
$signature = md5( $timestamp . '1002a612b4' );
// Replace with your own secret signature token. Example result:
// $signature = "ed8d12124fc7916b00e3ecd7dc2c1d6a"

Now use parameters signature and timestamp in your API requests. Example:


This URL would be valid for only 43200 seconds (12 hours), the default value of constant AFFTRACKERS_NONCE_LIFE.

To modify this duration, add the following to your config.php:
define( 'AFFTRACKERS_NONCE_LIFE', number_of_seconds );
(note this also affect all the internal links of AFFTRACKERS such as the ones to activate a plugin, delete a short URL, etc…)