I’ve created a Bit.ly class for PHP, which lets you easily cooperate with the Bit.ly API. Bit.ly offers you a service where everyone can generate a small, unique URL from a large and unhandy URL.
Requirements
- PHP
- cURL PHP extension. Further information: http://php.net/manual/en/book.curl.php
- A Bit.ly account. Sign up here: http://bit.ly/account/register
Example
Before you download the source code I would like to start by showing you how to use the Bit.ly class. Here is a small example:
<?php
require("bitly.class.php");
// Creating an instance of the bitly-class
$bitly = new Bitly();
// Setting the authentication for your Bit.ly user account. http://bit.ly/account/your_api_key
$login = "yourLogin";
$apiKey = "yourApiKey";
$bitly->setAuthentication($login, $apiKey);
// Getting a short URL by Bit.ly
echo $bitly->getShortURL("http://www.dennismadsen.com")."";
// result: http://bit.ly/8rPmdz
// Expand a short Bit.ly URL to the original URL
echo $bitly->getLongURL("http://bit.ly/7px4Q2")."";
// result: http://www.google.com/
// Get number of total click on a short Bit.ly URL
echo $bitly->getClicks("http://bit.ly/7px4Q2")."";
// result: E.g. 47000
// Get number of click by current bit.ly user on a short Bit.ly URL
echo $bitly->getClicksByMe("http://bit.ly/7px4Q2");
// result: E.g. 2
?>
All you have to do is to insert your Bit.ly username and your api Key. See http://bit.ly/account/your_api_key.
Download
Download Bitly.class.php (v. 1.0.1)
Please feel free to leave a comment below.





