Generate a UNIQUE ID like Youtube's Playlist - PHP
I have read this tutorial many times, finally, i finished to create my own unique id like Youtube.
But i can't find out how to create this kind of unique ID:
http://www.youtube.com/playlist?list=PL124C2FA58C814231
Some examples:
E5DBC5AD85E952BF F26D47E15E785137 4DE9165CE24633D0 26B44580D7ECDCD3 --- with prefixes PL -- PL3F16C0AE0309BB56 PL124C2FA58C814231How can i create that kind of unique id using PHP? My database used auto incremental PRIMARY KEY.
开发者_运维问答Thanks.
PHP has a uniqid()
function for this purpose. Pass the prefix to it as its first parameter:
$id = uniqid("PL");
// PL4e2b26588bec0
If this is needed for security purposes, there are better options discussed on the PHP document page.
Try this:
echo 'PL' . strtoupper(md5(time()));
Then obviously check your datasource to see if the value is unique.
精彩评论