I’m sure that by now you’ve seen smlnk, tinyurl, and the like, and probably wondered how it’s done.
It’s amazingly trivial, really. No, seriously. I wrote one myself, in about an hour. What took longest was making it work for both MySQL and PostgreSQL. Boredom is fun. :)
Really, all that they (more advanced shorteners) do is take your URL and generate a little code ‘key’, which it uses as an identifier to look up your entry.
Being small, lazy, and again, about an hour’s worth of work, mine simply uses the entry ID which is assigned to your URL upon insertion into the DB.
You’ll notice that unlike others, mine requests a password – this is merely so you can go back and remove your entry from the database, should you so choose.
Other trvial things to note is that aside from the id, I assign a timestamp to every entry, thus making it quite trivial to setup a system to wipe out all entries after XXX period of time – Of course, I’ve not implemented that.
You’ll notice my url shortener does anything but that. Why? Well, I have a looooong domain name.
It’s pretty trivial to use, though, just go to http://holwegner.com/r/ to be redirected to the manual entry system, http://holwegner.com/r/$ID to be redirected to that ID, or http://holwegner.com/a/MYURL to create a new link – sorry, there’s not yet any ‘text only’ URL reply function to test if you’re not using a browser.
I lack a tiny domain, though, so this service probably won’t get used too much, and I have no idea if I’ll do anything to make it any more usable. ;)
If you want the uglified PHP code, just drop me a note.