Create & copy shoter URL to clipboard

Today I’m going to share some work I did during the last couple of weeks. These days most of us make use of Tweeter, Buzz, etc … to update our status, pass some information, etc… . So in most cases when we want to share some interesting things found on web sites it’s convenient if we can get a shorter version of the actual URL generated within the site itself, because this can be very easily place among the content we want to share. In the mean time get it copied to the clipboard with a single mouse click. You might wonder why getting into this much of a trouble when there are enough freely available services (,,, etc…) to make the required URL shorter. The most important point is that we should always make sure that we make our user’s life easy with one go.

I found this interesting article on JustNI Blog that explained how to generate a shorter version of the true URL locally with the use of PHP and MySQL. His approach has provided a way to make use of the .htaccess file to handle the necessary url redirection.

His approach


Let me introduce my 2 cents to his approach by further extending the functionality to have the generated URL copied to the clipboard:

  • During each page load grab the page URL
  • Generate the corresponding shorter URL version if it doesn’t exists ( short database table).
  • Store that URL on the page(preferably inside a HTML hidden field).
  • Provide a button or image to get the URL copied to the clipboard ( Here it provides a comprehensive cross browser compatible, Flash supported jQuery based implementation of Copy to Clipboard ).
  • Place the URL redirection process related logic inside the index.php file.
  • Once the shorter version of the URL is requested, the logic on the index.php extracts the query string passed for url( ?url=AX37JEGJR335AK4RB ) part and check its corresponding longer/original URL stored inside the system( short database table). If exists then it takes the user to the corresponding page else shows the user a message like “Page not found – 404”.