phpsqlurlhashtinyurl

Generate a unique tinyurl-like ID but randomly (not mysql row id to base64)


I need to generate unique URL like tinyurl's: domain.com/pgDzs7, domain.com/ab4dh3 BUT (!) the problem is that I don't want users to have a possibility to view previous and next URLs by just changing last letters in the URL.

For example, if somebody creates a content which gets URL domain.com/pgDzs7, I want next visitor to get an absolutely different unique URL (for example, "ab4dh3") so nobody can't find out how these URLs have been generated and see content of other users unless they know its URL.

All I found here on Stackoverflow is to convert table's primary integer key into a base64 form. But I need different solution which is also will not generate collisions and doesn't have for/while cycles (if it's possible) since my MySQL table has dozens of GBytes.


Solution

  • I found a better solution. All I need is to shuffle the alphabet [a-zA-Z0-9] so visitors aren't able to iterate URLs. At least it won't be so easy as before.