how is create a unique tracking code [closed]

主宰稳场 提交于 2019-12-29 02:12:11

问题


how can create a unique tracking code?
What is your suggestion?

The number of characters not more than 10 and use only of number .
Please call example powerful...


回答1:


If you're willing to allow for a few more characters, and let your number be a hex number, the uniqid function will be useful to you




回答2:


How about using time();?? It will give exactly 10digits and will be unique forever with a difference of microseconds:)




回答3:


Because of maximum random number limits, you might use something like this:

$number = mt_rand(10000,99999).mt_rand(10000,99999);

Or use for loop as @JK posted. Then, you might check uniquiness of the number, and, if not unique, generate new...




回答4:


$random = "";
for($i = 0; $i < 10; $i++)
  $random .= mt_rand(0, 9);

However if you want something more powerful you should consider using characters as well:

$random = substr(base64_encode(sha1(mt_rand())), 0, 10);


来源:https://stackoverflow.com/questions/6884912/how-is-create-a-unique-tracking-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!