Skip to main content

Adfly URL Shortener PHP API

Now days, Adfly is one of the most popular url shortener service on the web. The best thing of this service is that you can earn money through this service and it is the main reason of it's popularity. Nowadays it is providing simple api to made this service more easy.

In this post you will show how we can make short url using Adfly api and PHP.


Step 1 - Get Your Adfly API Key & User ID

To use Adfly API at first you need to get your API key and your user id. If you are a Adfly member you can get these by following way..

Go to http://adf.ly/publisher/tools#tools-api

Here you will fond a link something like this..

http://api.adf.ly/api.php?key=7abccd03cc3005835dc61dd956b583ca&uid=111111&advert_type=int&domain=adf.ly&url=http://somewebsite.com

Here 7abccd03cc3005835dc61dd956b583ca is your API key and 111111 is your user id.

Step 2 - Adfly PHP Function

/**
 * Adfly Url Shortener PHP API
 * 
 * @param string $url http://www.google.com
 * @param string $key 7abccd03cc3005835cc61dd956b583ca
 * @param int $uid 1234
 * 
 * @param string $advert_type (optional) int || banner
 * @param string $domain (optional) adf.ly || q.gs
 */
function adfly($url, $key, $uid, $domain = 'adf.ly', $advert_type = 'int')
{
  // base api url
  $api = 'http://api.adf.ly/api.php?';

  // api queries
  $query = array(
    'key' => $key,
    'uid' => $uid,
    'advert_type' => $advert_type,
    'domain' => $domain,
    'url' => $url
  );

  // full api url with query string
  $api = $api . http_build_query($query);
  // get data
  if ($data = file_get_contents($api))
    return $data;
}

Usage:

// Your api key
$apiKey = '7abccd03cc3005835dc61dd956b583ca';
// Your user id
$uId = 111111;

echo adfly('http://w3bees.com', $apiKey, $uId);

Output:

http://adf.ly/Wtvpt

Popular posts from this blog

Multiple File Upload with Progress Bar using PHP & jQuery

Some days age I have created a post that deals with How we can upload file with progress bar using php and jQuery . Some of my readers asked me how we can upload multiple files with progress bar. In this post I am going to show you how we can upload multiple files with progress bar. We can upload multiple files with progress bar exactly same way as I shown previous. But we need to do some modification with our file upload form and our php script to handle multiple files.

Multiple File Upload with PHP

Sometimes we need to allow our users to upload multiple file upload. On my previous post I was shown the basic of simple file upload with PHP. Today I am going to show you how to allow users to upload multiple files. It is almost similar like simple file upload but we need to do some modification with html markup and php code . multiple attribute is needed to add on the html markup. Major web browsers like Firefox, Chrome, Safari and IE 9+ support this attribute. Now I am going to show you how to upload multiple file with PHP and basic HTML form.

File Upload with Progress Bar using jQuery and PHP

In this post you will learn how to create a AJAX file uploading system with progress bar using jQuery and PHP. For this purpose we will going to use jQuery Form Plugin . It is a easy to use and powerful jQuery AJAX form submitting plugin. It supports XMLHttpRequest Level 2 and iframe file transportation. That's why it will work for both old and new browsers.