I have several users and I would like to generate a referral url for each of them, but I don’t think it would be nice to have something like
http://domain.com/myusername
I would prefer to buy myself a shorten domain and transfor that myusernameinto something smaller, but not generated using the database so it would be easy to manage and no need to have a special table for this.
kinda like Dropbox does, as my referral is: http://db.tt/jnYosez
is there a simple way to change between a string into a short string and vice versa … or I can always use the User ID if I’m force to use numeric … maybe converting to other number base ?
Any idea is mostly appreciated 🙂
You can’t do it inhouse without using a database. It’s because the names are short and therefore it’s likely that a name have been used before.
You need to generate a name (using randomness or an algorithm), check if it exists and then store it in the db.
Update
Here is a solution:
You can shorten the numbers even more by adding more that are allowed in uris.
Theres probably a more efficient way to do it. Bitwise operations isn’t really my area.
Update 2
Which means that you can use those to shorten the url (unless your web server is using them for something else)