the description

While doing research on how to make vanity URLs based on usernames for a separate project, I stumbled upon a little snippet of .htaccess code that passes part of the requested URL as a _GET variable to any script. That automatically made me thing "so that's how URL shorteners work". I assumed the only other thing it took was a database with all of your redirect URLs and shortened URLs paired up, and a script with a header() function call. Easy, right? Not quite...

At it's essence, my URL Shortener is that basic concept, but it's significantly more complicated than I originally thought. I needed a form that could be used to create the shortened URLs, and then a way to store rudimentary stats like click-counts. I'm working on improving my object oriented coding, so I decided that was the best way to create this app. I tried to make the objects as simple to implement as possible, limiting the number of method calls necessary from the creation/redirection script.

And that's another thing: all of the logic is being handled by a single page (redirecting, short url creation, and stat checking). I didn't use an MVC framework, so having both view and control in the same file forced me to keep the control scripts concise. Having all 3 main functions of the site on one page made debugging a pain, but since I kept my objects so tight the actual script has very little controller code on it.

the link