开发者

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

PL124C2FA58C814231

How 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜