DEV Community

loading...
Cover image for php link shortener (simplelink)

php link shortener (simplelink)

johnny-choo
・1 min read

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

Github:
https://github.com/johnny-choo/simplelink

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

Discussion (5)

Collapse
suckup_de profile image
Lars Moelleken

Your URL validation is not very solid: johnnychoo.000webhostapp.com/Foo2/

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. 🙋

Collapse
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.

Collapse
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?

Thanks.

Collapse
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 example.com/file. 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 bit.ly 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.

Collapse
siarhei_siniak_marketing profile image
Siarhei Siniak • Edited
  1. links 1.1. github.com/topics/url-shortener 1.2. github.com/luke10x/urlshortnr 1.3. github.com/YOURLS/YOURLS 1.4. github.com/738/awesome-url-shortener 1.5. polrproject.org/ 1.5.1. demo.polr.me/shorten 1.5.2. docs.polrproject.org/en/latest/use... 1.5.3. github.com/cydrobolt/polr 1.5.4. github.com/fauskanger/mypolr 1.5.5. github.com/ajanvier/docker-polr a docker image, a single onliner to spawn the service. 1.6. github.blog/2011-11-10-git-io-gith... towardsdatascience.com/github-url-... interesting interface via curl, yet only restricted to github.com 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.