Why you should not write a url shortner tool

  25 Jun 2024


Some time ago I asked myself “how hard is it to make a URL shortener service?”, you know, one like tinyurl and bitly. So I dusted off my php skills and I did it.

This was surprisingly easy to pull of. After all, it was just a matter to write a simple form with a url to shorten, an optional expiry date, and the script just inserted a row in a table with the code and the corresponding url, and a simple check to redirect only if the shortened link is not expired. Content with my job, I left it there in case I every needed it, since I took the time to write it, just as well use it right?

Then, one day, I had the idea to check the database, and see if someone randomly come up to it and used it. I don’t how, that would happen, but I was doing some database maintenance anyway.

And it’s good I checked, because someone indeed had used it.

Strange urls database

Now, you should know I never actually posted any shortnened link. That means somehow a crawler must have found and recognized my site as a url shortener and started creating links with it. I have censored the actual links, but every single one of them is some kind of porn/scam website. As you can see, an additional feature I added was a counter to see how many times a certain link is accessed, one got more than 800k clicks!

Now, keep in mind I didn’t implement any kind of spam check/authentication. Still, just don’t do this, it’s dangerous. You website might be blacklisted and if illegal content is shared with your links, you might even get in trouble. It was a fun little project, but be careful.