如何创建唯一的ID,例如YouTube? [英] How do I create unique IDs, like YouTube?
问题描述
我一直想知道他们这样做的方式和原因……例如: http:// youtube .com / watch?v = DnAMjq0haic
I've always wondered how and why they do this...an example: http://youtube.com/watch?v=DnAMjq0haic
这些ID是如何生成的,因此没有重复项,与使用简单的自动方式相比有什么优势
How are these IDs generated such that there are no duplicates, and what advantage does this have over having a simple auto incrementing numeric ID?
如何使它简短但又保持唯一性? uniqid创建的字符串相当长。
How do one keep it short but still keep it's uniqueness? The string uniqid creates are pretty long.
推荐答案
Kevin van Zonneveld写了出色的文章包括一个PHP函数来完全做到这一点。他的方法是我研究此主题时发现的最好方法。
Kevin van Zonneveld has written an excellent article including a PHP function to do exactly this. His approach is the best I've found while researching this topic.
他的功能非常聪明。它使用固定的$ index变量,因此可以删除有问题的字符(例如,元音,或者避免O和0混淆)。还可以选择混淆ID,以使它们不容易猜测。
His function is quite clever. It uses a fixed $index variable so problematic characters can be removed (vowels for instance, or to avoid O and 0 confusion). It also has an option to obfuscate ids so that they are not easily guessable.
这篇关于如何创建唯一的ID,例如YouTube?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!