I want to write my own URL shortener using php and mysql as a tester to see how much I know about the two languages? However I don’t know what is needed to do so or where to start. Please could someone give me a list of what needs to be done in order to create/write a successful URL shortener?
Share
All you need is a short domain name.
Then you can have a simple MySQL table with two columns: Id (the primary key with auto increment) and Url. Which should probably be a TEXT or something. Since varchar 255 might be too short.
Then set up your .htaccess so that a url like domain.com/a21s1 gets converted to domain.com?url=a21s1
That’d be something along the lines of:
Then in php do something like:
You’d also want to have sanity checks when users input a new url to add you would regex it to make sure it’s a url, and if it’s missing
http://prepend it to the url.