Tag Archives: url shortener

How to Preview a Shortened Google URL (goo.gl) Tips, Tricks and Tutorials 06 AUG 2014

sexy-hot-google-girlActually, there is a pretty nifty trick if you want to dereference (preview) a shortened goog.gl link (that was created using the Google URL shortener) in order to make sure that it isn’t linking to something dodge like 9gag.com.

To see where a shortened goo.gl link points to, paste the shortened link with a plus at the end into your browser and hit go. (So if link is http://goo.gl/KDQsVr enter http://goo.gl/KDQsVr+ into your browser.)

Google will then bring up an analytics page showing you the link, how many times it has been clicked on, where it points to, as well as the associated QR code. It even has stats on referrers, browsers, countries and platforms.

Very useful indeed, and apparently this trick works for bit.ly shortened links as well.

Outside of that, there are also a number of websites out there that perform the same function, longurl.org for example being one of them.

Related Link: https://goo.gl/

Quick and Dirty PHP URL Shortener Software & Sites 27 JUN 2013

github logoAn URL Shortener isn’t a particularly difficult piece of code to write, nor implement. Basically it is nothing more than creating a short unique string and associating it with a full URL, with some redirect code written to handle any incoming short code links.

That said, just because it’s easy doesn’t necessarily mean that I feel like writing my own version right now, which is why it was super useful to come across Brian Cray’s nice, simple and very portable PHP-URL-Shortener project (on GitHub) that makes it a snap to get a quick and dirty URL shortener system running on one of your hosted domains.

Setup is little more than creating a database and user account in which to store the links, upload the provided files, edit the config file, and rename the .htaccess file. Literally a five minute job!

You can shorten links both manually (by browsing to the location you installed to) or programmatically via the supplied API.


Related Link: https://github.com/briancray/PHP-URL-Shortener

PHP: How to Shorten an URL using the Google URL Shortener API Programming 22 FEB 2013

The shortening of URLs has become quite popular as the advancement of mobile phones picked up speed, and for the most part the science of generating a short URL given a long URL is pretty elementary stuff.

Today’s PHP function looks at how one can quickly generate a short URL from a long URL by making use of Google’s excellent URL Shortener API.

Now of course, requests to the Google URL Shortener API for public data must be accompanied by an identifier, which can be an API key or an auth token. 99% of the time an API key will suffice for your purposes, so to acquire an API key, visit the APIs Console and in the Services pane, activate the Google URL Shortener API. Next, go to the API Access pane. The API key is near the bottom of that pane, in the section titled “Simple API Access.”

After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs. Note that the API key is safe for embedding in URLs – it doesn’t need any encoding.

Now that we have our API key, let’s take a look at the function which is going to generate our Short URLs for us:

//generate a short URL using Google URL Shortening API
function googleGenerateShortURL($longurl) {
    //result object to be returned at the end of the function
    $result = array('status' => '0', 'short-url' => '', 'long-url' => '', 'message' => 'Failed to shorten URL.');

    if (strlen($longurl) > 0) {

        //build up the options array to be fed into the stream_context object
        $opts = array('http' =>
                'method' => 'POST',
                'header' => "Content-type: application/json\r\nX-Requested-With: XMLHttpRequest\r\n",
                'content' => json_encode(array('longUrl' => $longurl, 'key' => '#YOUR-GOOGLE-API-KEY#'))

        //attempt to hit the Google API url using a file_get_contents call using our crafted stream context
        try {
            //create stream context using our special options
            $context = stream_context_create($opts);
            $queryreturn = file_get_contents("https://www.googleapis.com/urlshortener/v1/url", false, $context);
            //decode the returned JSON object
            $jsondata = json_decode($queryreturn, true);

            if ((key_exists('id', $jsondata)) && (strlen($jsondata['id']) > 0)) {
                $result = array('status' => '1', 'short-url' => $jsondata['id'], 'long-url' => $jsondata['longUrl'], 'message' => 'Succesfully generated short URL.');
        } catch (Exception $e) {
            $result['message'] = 'Failed to shorten URL. Unable to connect to Google\'s API service.';
            $result['exception'] = $e->getMessage();
    } else {
        $result['message'] = 'Failed to shorten URL. No long URL provided.';
    return $result;

If successful, the function will contain a ‘status’ set to 1, as well as the shortened URL stuffed into the ‘short-url’ key of the function return object.

So not exactly rocket science then, but definitely something rather nifty and even better, time saving!

Shorten Your URLs the Bit.ly Way! CodeUnit 29 JAN 2010

URL shorteners are all the rage at the moment, made particularly popular by the advent of micro-blogging platforms like Twitter and even FaceBook updates for that matter. The concept is pretty simple. Take a long URL, pass it on to the shortening service and receive a far more compact URL that points to the original URL.

Obviously you can see the advantage of this.

Now I must admit that my favourite shortener at the moment (and believe me, there are many of these services out there) is bit.ly.

Aptly support by its bright blowfish mascot, bit.ly performs the basic URL shortening function quickly and with minimal effort, but at the same time enhances the experience with a friendly, quick and quite usable user interface.

On top of all this, they then throw in a whole lot of extra services like tracking shortened URL clicks, storing your converted URL history, and registering a host of other stats against all manner of shortened URLs, never mind all the goodies if you upgrade to a Pro account.

Pro account? Yup, believe it or not, they’ve even managed to figure a way of monetizing this particularly simple concept!

In any event, what I really want to say is that they offer a pretty damn good service – even if it is something as simple as shortening your URLs for you! ;)

Related Link: http://bit.ly