I have always wondered why and how edge in the game...a good example: http://youtube.com/watch?v=DnAMjq0haic

How are these IDs produced so that you will find no replicates, and what advantage performs this have over getting an easy auto incrementing number ID?

How can one ensure that it stays short but nonetheless keep it's originality? The string uniqid produces are pretty lengthy.

base62 or base64 scribe most of your key's value then store it in another area.

example base62 for primary key 12443 = 3eH

saves some space, and that's why i know youtube is applying it.

carrying out a base62(A-Za-z0-9) scribe in your PK or unique identifier may prevent the overhead of needing to determine when the key already is available :)

Auto-incrementing may be easily indexed. These can't be predicted, and for that reason can't be sequentially indexed.

I would recommend using a double-url format (Like the SO Web addresses):


Should you needed both id, and also the title within the url, you can then use simple amounts like 0001, 0002, 0003, etc.

Producing these secrets can be very simple. You could utilize the uniqid() function in PHP to create 13 chars, or 23 with increased entropy.

A method to get it done is as simple as a hash function with unique input each time.

example (you've labeled the question with php therfore):

$uniqueID = null
do {
  $uniqueID = sha1( $fileName + date() );
} while ( !isUnique($uniqueID) )

There must be a library for PHP to create these IDs. Otherwise, it isn't hard to implement it.

The benefit is the fact that later you will not have title conflicts, whenever you attempt to reorganize or merge different server assets. With number ids you would need to change a number of them to solve conflicts which can lead to Url change resulting in Search engine optimization hit.

A lot of this is dependent on what you ought to do. How 'unique' is exclusive? Are you currently serving in the unique ID's, and will they mean something inside your DB? if that's the case, a consecutive # may be ok.

However, if you are using consecutive #'s someone could methodically steal your articles by iterating through the amounts.

You will find filesystem instructions which will generate unique file names - you could utilize individuals.

Or GUID's.

Think about using something similar to:

$id = base64_scribe(md5(uniqid(),true))

uniqid will enable you to get a distinctive identifier. MD5 will diffuse it providing you with a 128 bit result. Base 64 encoding that provides you with 6 bits per character within an identifier appropriate to be used on the internet, hitting the scales around 23 figures and computationally intractable to guess. If you wish to be much more paranoid ugrade from md5 to sha1 or greater.

Outcomes of hash functions like SHA-1 or MD5 and GUIDs often become very lengthy, that is most likely something you wouldn't want. (You've particularly pointed out YouTube for example: Their identifiers stay relatively short despite the bazillion videos they're hosting.)

For this reason you might like to consider transforming your number IDs, that you simply are utilizing behind the curtain, into another base when putting them into Web addresses. Flickr e.g. uses Base58 for his or her canonical short Web addresses. Particulars relating to this can be found here: http://www.flickr.com/groups/api/discuss/72157616713786392/. If you're searching for a normal solution, take a look in the PEAR package Mathe_Basex.

Please be aware that even just in another base, the IDs can nonetheless be predicted from outdoors of the application.

If you would like short Web addresses and of a routine isn't a concern, you are able to convert the auto-incrementing ID to a higher base.