Shorten URL using Adfly API in PHP

In previous tutorials I have explained shorten URL API of Google and Bitly. Now in this tutorial I will show you how to Shorten URL using Adfly API in PHP. It is one of the most popular URL shortener service provider. Also you can earn money through this service, that is the main reason of it’s popularity. It is providing an API to easily implement this service.

To get the API key, create an account on and get your Adfly API key and User ID on You will found a link like below:

Here c3948ea56e6b536a0b945d1f55369e2c is your API key and 11775555 is your user ID.

/* Shorten Long URL */
function adflyShortenURL($url, $uid, $key){
	$apiURL = '';

	// api queries
	$query = array(
		'key' => $key,
		'uid' => $uid,
		'advert_type' => 'int',
		'domain' => ''

	// full api url with query string
	$apiURL = $apiURL . http_build_query($query).'&url='.$url;

	// get data
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $apiURL);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );

	$data = curl_exec($ch);
	return $data;


Now you can use above function as below:

$uid = '11775555';
$key = 'c3948ea56e6b536a0b945d1f55369e2c';

// Shorten a URL
echo adflyShortenURL("", $uid, $key);

You will get the result of above like below:

I hope this tutorial will help you to shorten URL using Adfly API in PHP.