|
Posted by howachen on 12/17/91 11:55
Alvaro G. Vicario 寫道:
> *** howachen@gmail.com escribió/wrote (11 Aug 2006 01:59:53 -0700):
> > Nowadays, many site use encrypted resource ID, rather than plain
> > numeric ID, such as the following:
> >
> >>> http://www.youtube.com/watch?v=p_YMigZmUuk
>
> This is not encryption, it's just a random ID (or maybe a hash). The more
> different chars you use, the shorter the string can be.
>
> > "p_YMigZmUuk" will be mapped into a database unique ID (numeric, auto
> > increment).
>
> I'd just store it as string and unique key.
>
> > What kind of encryption in PHP is the best in handling this job?
>
> You can calculate hashes with md5(), crc32() or sha1(), but you must be
> aware that hashes are one-way: you can't get the original string back.
>
> For random strings, you can use uniqid() or you can write a custom function
> using mt_rand().
>
well, to store md5() string in the datbase as the primary key is not a
good choice, since when performing table join, the speed is the trade
off. Also, the size of the row will become bigger.
[Back to original message]
|