Create your own URL Shortening Service

create your own url shortening service on your blog or website using this free scriptThere are a plenty of URL shortening services around that are both free and easy to use. URL shortening services are highly important when you have to share an interesting link with your friends or contacts online and don’t want to pass on an ugly URL which might just get chopped off at the other end, rendering it useless. URL shortening services such as TinyURL have become highly popular in the recent past. It becomes easy for one to share a link online be it on Facebook, MySpace or Twitter using a URL shortening service. So I was just wondering if I could have my very own URL shortening service which I could use personally or allow visitors on my blog to use it. So I Googled for a while and picked up a tiny class written in PHP, modified it as per my taste and bang! I have my very own URL shortening service here called Linx! Some of my friends were interested in applying this on their blogs/websites as well so I have decided to put it up here.

First of all, if anyone of you is wondering why I should have my own URL shortening service. Well here are a few good points;

– Every time you find an interesting link you want to share with your friends and if your link looks something like, you’re not just passing on a link but you’re passing on your website name. Publicity!

– Links are destined to go viral. So if around 1000 people love the content, they’ll pass on the link further. If even 2% of them case about the part, bang! You’ve got traffic baby!

I’m sure there are a plenty of more reasons you’ll find to suit your needs. Anyways here’s all the information on the script part you’ll need to get started.

HarryJerry Linx 1.0

What is this script all about?

– HarryJerry Linx is a simple script written entirely in PHP and uses a MySQL database to create short URLs out of big bad ugly ones.
– It produces URLs of the form:


How to download the script?

Click here to download the HarryJerry Linx script. It’s tiny (just a little over 5KB) and won’t take more than a second.

How to install the script?

– There’s a nice little shiny page included with the script, titled ‘Read me’, and it’s really great if you read it. I have included all the installation steps from a very basic point of view. It’s very easy to install and takes only 5 minutes.

What are the minimum system requirements?

– You’ll need a web hosting account with PHP/MySQL support. That’s it!

How about support?

– In case you face any problems you can post them here (on the comments section), e-mail me at [email protected], contact me on Twitter (harry_jerry). I can also offer you free installation services, just in case.

Future Development

I have a few more ideas on this script. I’ll be working on them regularly and updating the script to add extra functionality. In case you like Harryjerry Linx, please post your feedback.

56 Replies to “Create your own URL Shortening Service”

  1. Harry,
    For a project of mine, that will be powered by wordpress, it would be great, If the script could produce a shortened URL for every post, when it is published.

    Am I asking to build Google ? 😀

  2. You rock! Seriously. Mucho Kudos. I’ll be sure to post once I get the script running. Also, you’ve just been favorited! 😛

  3. And now I am getting the following error:

    Warning: Cannot modify header information – headers already sent by (output started at /home1/shamaror/public_html/emet/r/includes/conf.php:1) in /home1/shamaror/public_html/emet/r/index.php on line 82

    Any ideas what is wrong?

  4. @Lee: I guess you edited the script using Notepad. Make sure there are no blank lines at the end of the script files. Now do a re-upload and it should work fine.

    As of now you can’t have links outside the subdirectory. I’m working on another edition of the script which shall allow this feature.


  5. One other question. Is there a way to stop others from finding/using the script? I tried a password but then, of course, that required anybody who wanted to use the short URL to know the login also.

  6. Simple, easy to install & use script here. Props! One question: is it easy to create a bookmarklet for this – similar to’s? People could drag it into their bookmark bar and click it whenever they want to shorten a URI with your Linx installation.


  7. @Lee: Yes you can’t simply apply a password like that, I’ll include this feature in the next release for sure.

    @Adrian: Thanks for the feedback! Yup that’s a great idea, a bookmarklet would be great!

  8. Hi, I got these errors when trying to create my first URL:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/moses/public_html/harryjerry-linx/includes/hjurl.php on line 19

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/moses/public_html/harryjerry-linx/includes/hjurl.php on line 73

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/moses/public_html/harryjerry-linx/includes/hjurl.php on line 123

    Any help would be greatly appreciated.


  9. Hi,

    I actually figured it out, I imported the SQL table file to the wrong database 🙁

    Just wondering for SEO purposes, are the redirect links 301 or 302? If they are 302 can we change them to 301 somehow?

    Thanks again for this wonderful script!

  10. I have uploaded your script and added the database to the SQL database when i create my link the data is inputted into the SQL database but when i try and visit a URL i have shortned i get a 404 error. I am not really sure why any ideas?

  11. Great script Harry! Thanks 🙂 just one question – my shortened URLs are coming out as //1 or //2 etc. They still work as I have fiddled with the htaccess but any ideas on how to stop this happening? Thanks 🙂

  12. Can the shorturl script be customized to change a parameter to only a single address?

    Instead of “any” url, the shortened url would be a predetermined one, with the “customization” being parameters added to the predetermined url.

    Such as:
    to be shortened to the shorturl…

    ECS Dave

  13. if anyone has problem with // showing in URL like ‘Fergus’ has above (comment 25), then open index.php and look for:

    if ( REWRITE ) // mod_rewrite style link
    $url = ‘http://’.$_SERVER[‘SERVER_NAME’].dirname($_SERVER[‘PHP_SELF’]).’/’.$lilurl->get_id($longurl);

    remove / from betweem .’/’. and save the file.

    If someone has problem with site not working, or url’s not working then replace all the content in .htaccess file with this:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    happy shortning or urls 🙂

  14. Another implementation of your script.

    Thanks for great script.

    Few Features if you can code:
    1. Check if URL is in proper format or not
    2. Number of hits on each URL
    3. Option to enable/disable CAPTCHA
    4. When new short URL is generated, automatically copy it to Clipboard.
    5. One admin page, where there is a grid which will list all the URLs.

    Would appreciate it. Thanks.

  15. Thanks for the support guys! Some lovely implementations I’ve seen. I’m working on an update now, keeping in mind some of your suggestions. I’ll be posting it online soon.

    Thanks again!

  16. Dear Everyone!

    If problem the css, js, etc… query in the index.php write this line in the .htacces file:

    RewriteCond %{REQUEST_FILENAME} !-f

    and voila! 🙂

    Best: Roland

  17. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx on line 123

  18. Hmm…. This script looks and works exactly like lill-url script. INFACT this script as references to it all over the place…

    But it cant be the same right? since Harry is working on a updates and everything.

    Its okay if your using there base, but are there any changes from theres/his from yours? just to kind of compare?

    1. It’s based on a script as I have mentioned above in the post as well. It’s based on two open source scripts, I’ve modded them and yes of course I am providing support! 🙂

  19. Harry, No disrespect, and sorry if I came off that way, but any word what what changes there are from your to lil-url? Just trying to figure out, if yours is the way to go or if I should use theres?

    again, not disrespect, and thanks so much for taking a script with no support and having your friends here as well as you self provide awesome support, since lil-url’s author does not provide any support at all.

  20. Works great.. I was wondering however, am I supposed to get a forward slash “/” character as a shortened URI character? eg: instead of

    1. Go to index.php line 41:
      $url = ‘http://’.$_SERVER[‘SERVER_NAME’].dirname($_SERVER[‘PHP_SELF’]).’/’.$lilurl->get_id($longurl);

      Get rid of the .’/’ bit so it reads:
      $url = ‘http://’.$_SERVER[‘SERVER_NAME’].dirname($_SERVER[‘PHP_SELF’]).

Leave a Reply

Your email address will not be published. Required fields are marked *