URL shortening is a technique in which url made substantially shorter in length and still direct to the required page. This is achieved by using an HTTP Redirect on a domain name that is short, which links to the web page that has a long URL.
Short URL is convenient for microblogging which has a 140 character limit. Here in this article I am describing url shortner in PHP using bit.ly
Step 1: get the key and username from http://bitly.com/a/your_api_key (you may require to register) this will provide you the BITLY USERNAME and BITLY API KEY
Step 2: Now from your PHP code you need to pass the key and url which you want to shorten and the username.
function get_short_bitty_url($key, $url, $username)
$ch = curl_init("http://api.bitly.com/v3/shorten?login=$username&apiKey=$key&longUrl=$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$json = json_decode($result, true);
return $json['status_code'] == 200 ? $json['data']['url'] : false;
This function will return false if bit.ly could not shorten the url for some reason else it will return the short url of the passed long url.
Note: This code is running at the QueryHome.