Press enter to see results or esc to cancel.

How to do QR Codes and Short URLS properly

Recently, I’ve been working with QR Codes and URL Shortening, I thought I’d let you know about my experiences, I’ve learned a few useful tips along the way!

I was trying to create a single qr code that could be scanned by users so that it would eventually take them to the app store most relevant to their device.  The best thing is that you can do all of this for free using tools that are available online for no charge.

Create the Url to shorten

First I needed to create a URL, this was easy as all I had to do was create a php script that was placed on a server, it look like this:

// get the user agent string, this tells us what browser (device type) the user has
$checker = array(
    'iphone' => preg_match('/iPhone|iPod|iPad/', $ua), // checks for the strings iPhone, iPod, or iPad
    'blackberry' => preg_match('/BlackBerry/', $ua), // checks for the string Blackberry
    'android' => preg_match('/Android/', $ua) // checks for the string Android
// at this stage the $checker array contains three boolean items, usually only one of them will be true
if ($checker['iphone']) {
    // user has an iphone
    header('Location:', 301);
} elseif ($checker['android']) {
    // user has an android 
    header('Location:', 301);
} else {
    // either user has a blackberry which no one wants anymore or we couldn't match a device
    // redirect to a fallback url
    header('Location:', 301);

Once this was deployed to my server, it looked like:

This url is quite long, and we know that QR Codes that have more data in them look more detailed and complex, so we need to shorten this url, to the rescue!

Why use

Simple, it provides all of the functionality you need and a lot more besides including tracking of each click (or visit) and when and where in the world it was accessed from, plus you can create a whole library of them.


Now the resulting Url us much shorter:

If we turn this into a QR Code. it should allow us to make it smaller, and less complex, making it even faster to scan. Profit!



Leave a Comment