DEV Community

Cover image for php link shortener (simplelink)

php link shortener (simplelink)

・1 min read

I created a very simple php link shortener without need of any database.


Come support me by giving me a star.Thank you.

Discussion (5)

suckup_de profile image
Lars Moelleken

Your URL validation is not very solid:

With e.g. this as input

"); echo file_get_contents("../index.php"); // (https://)

so I can upload every php command that I want.

I would use the strpos check with 0 instead of false (so that we protect us against something like "file://" + a build in URL check from php: FILTER_VALIDATE_URL

If you have more question, please contact me, I am happy if I can help. 🙋

johnnychoo profile image
johnny-choo Author

Hi Lars Moelleken,

Really appreciate your comment. I have updated my code following your advises.
Pls check it out and if possible feel free to contribute to this project. This project needs a better UI and some extra features.

siarhei_siniak_marketing profile image
Siarhei Siniak

Hey, johnny-choo! That's amazing that you've made an open source tool yourself. I'm doing product development mysef. And the first question that pops up in my mind is:

  1. what for to create something that definitely has been invented 100 times. I'm pretty sure that just googling on github would provide a set of open source url shorteners. No guarantee that is to be created in PHP and DB less. Yet anyway.

Did you have some product idea in your head before making this one?
Maybe you've been not satisfied with some other url shorteners. I mean, what was the incentive to spend the time on this project?


johnnychoo profile image
johnny-choo Author

Hi Siarhei Siniak,

Thanks for commenting.

My initiative for this project is to make sending links easier for everyone.

For example, I use it to rename my link, like my Google drive link is very long and I can shorten it into When I want to send to anyone, I do not need to copy and paste but just type it out.

All project idea didn't come out from nowhere. The idea of creating this project pops up is when I face problem with which I can't get short link that I want for many times that I need to keep renaming it and sometimes I am only able to generate random short URL.

This is why I started building my own URL shortener website.

To start this project, I actually search through the internet but I unable to find any open source project which is easy to setup.All needed mysql database and some that not need database uses flat file database like storing it in JSON file which I think is not good when storing large number of URL it will be slow redirecting as it takes time to read the file and find the URL and it is difficult to delete short URL which is not wanted anymore.

My plan is to host this website in free hosting platform like 000webhost or infinity free and all these platforms you can upload file through online file manager. Although they offer mysql database but I am lazy to create a database and do configuration change for other php URL shortener open source project. Therefore, I created my own URL shortener from scratch.

I recommend you to use simplelink too. You can create your own URL shortener in just 2 steps (download and upload the code) and with only 2 files. Lastly, give me a star in GitHub for supporting. Thank you.

siarhei_siniak_marketing profile image
Siarhei Siniak • Edited
  1. links 1.1. 1.2. 1.3. 1.4. 1.5. 1.5.1. 1.5.2. 1.5.3. 1.5.4. 1.5.5. a docker image, a single onliner to spawn the service. 1.6. interesting interface via curl, yet only restricted to urls.
  2. Well, there're pretty quite many url shorteners on github. polr is open source, written in PHP, has a docker image that gives a simple one liner to make it running. If you are really concerned with MySQL configuration, make sense just to refactor that project to use some in memory database, reddis perhaps.