Just as a fun project I wanted to try and make a simple URL shortener for my own personal use but I wanted to try and incorporate things that I liked from other shorteners like bit.ly and such. So I've come to a snag when it comes to assigning short URL IDs.
Right now I just manually assign the code but I would like to automate it. I could do it the easy way by just assigning incrementing IDs (I thought this could be done using an assigned auto increment value on the MySQL database and just use the PHP dechex()
function for the URL) but it seems that other shorteners are random.
I know that I won't get an absurd number of URLs in the database but I still want to keep the process efficient which makes creating random unique IDs rather taxing with many URLs in the database. I don't really have any idea about how to go about making a system to make the IDs that doesn't make duplicates and doesn't run slowly.
See: PHP short hash like URL-shortening websites and the answer you might want: http://blog.kevburnsjr.com/php-unique-hash
The second link might be particularly useful, just short-hash the current ID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With