Easily create short URLS with php, curl and goo.gl or bit.ly

The 140 character limit in twitter has made the necessity of URL shortner services. There are many URL shortening services available like http://goo.gl, http://bit.ly, http://ow.l etc.. You can even have your own short URL service, if you are so much worried about your brand. Deciding which type to use is surely a decision based on your business and revenue stream. If you are getting a majority of your business on Twitter, or if you have an extremely long URL and need to shorten it up for print, social media, television, or other advertising to help make it memorable, then a custom shortened URL is probably the way to go for you. Also, if you want 100 percent control over your content and your identity, then you should also be shopping for your own shortened identity.

For the rest of you, maybe goo.gl will suffice, or maybe registering hybrid bit.ly or awe.sm customized URL will fill the gap. Through this tutorial we are going to help these sort of people who are not so worried about their brands.

How to create short URL with Goo.gl and php

It is easy to create short URL’s with Google’s URL shortening service, http://goo.gl. Use the following code. You need to have curl enabled in your server. You also need to get an API Key from http://code.google.com/apis/console/

You can also use the service of http://bit.ly another popular URL shortening service. The only demerit with them is that, you need to have an account with them. Here is the php code to create short URLs with bit.ly

To show the short URL, simply

Thats it. If time permits, we will add codes for doing the same with other service providers too. Also the code for the reverse too, that is to get the original URL from a short URL.

We have released a plugin for elgg with the above code, which you can download from the elgg community.