uniqid
(PHP3 , PHP4)
uniqid --- 產生唯一的 id
語法 :
int uniqid(string prefix [, boolean lcg])說明 :
uniqid( )傳回目前時間百萬分之一秒的一個唯一的identifier,如果你同時地在數個主機上產生identifier,可能會發生在相同的百萬分之一秒上產生identifier,這時便可使用參數prefix,參數prefix可以到114個字元長。
如果非必需的參數lcg設為true,uniqid( )將會在傳回值的後面增加額外的"combined LCG",這可使結果更加的獨一無二。
空的prefix,傳回的字串將會是13個字元長,如果lcg為true,則會是23個字元長。
注意 : 參數lcg只有在PHP4和PHP3.0.13和較新的版中才有效
如果你需要一個唯一的identifier或是標記,並且你打算要經由network(例如 : session cookies)來公佈這個標記,你可以這樣使用 :
Example :
<?php
$token = md5 (uniqid ("")); // no random portion
$better_token = md5 (uniqid (rand())); // better, difficult to guess
?>
這將會產生出32字元長的identifier。