当前位置:网站首页>PHP generates unique strings

PHP generates unique strings

2020-11-08 16:17:00 Back as a teenager

php Unique string generation mode uniqid ......

  • High concurrency 32 Bit unique string ;
  • Variable unique string ;
  • The order number is unique ;
  • Low frequency 13 Bit only string ;
 Generate initial password 
$salt = substr(uniqid(rand()),-6);
$key = 'xx.xxx.com';
$pwd = md5(md5('123456').$salt.$key);

 Generating uniqueness id Several ways to 
uniqid(); 13 A string 
uniqid('',true); 23 A string 
md5(uniqid(mt_rand(1,10000)));32 A string 
md5(uniqid(md5(microtime(true)),true)); 32 A string 
md5( uniqid( md5(microtime(true)),true ) . mt_rand(1,10000) );32 A string 
session_create_id()

// establish 24 Bit unique value  14+6+4 20140507115523 123456 1234
date('YmdHis').substr(microtime(),2,6).mt_rand(1000,9999); 

    1. uniqid() 13 A string
$units = array();
for ($i = 0; $i < 3; $i++) {
    $units[] = uniqid();
}
var_export($units);
array (
  0 => '5fa799bee9f7e',
  1 => '5fa799bee9f95',
  2 => '5fa799bee9f96',
)
    1. uniqid() 23 A string
$units = array();
for ($i = 0; $i < 3; $i++) {
    $units[] = uniqid('', true);
}

var_export($units);
array (
  0 => '5fa79a8371e2b9.16693379',
  1 => '5fa79a8371e573.86696425',
  2 => '5fa79a8371e5a8.44085231',
)
    1. uniqid() 32 A string
$units = array();
for ($i = 0; $i < 3; $i++) {
    $units[] = md5(uniqid(mt_rand(), true));
    // $units[] = md5(uniqid(md5(microtime(true)),true))
}

var_export($units);
array (
  0 => '56d06914ee44c0f568be745edf1410de',
  1 => '914a38fe5a2b3124bc42593b39c12a22',
  2 => 'fa4853979a3e6d19748c9b354f034d49',
)

Reference link

版权声明
本文为[Back as a teenager]所创,转载请带上原文链接,感谢