[PHP] 生成随机数(混合),字母大小写加数字,纯数字 →→→→→进入此内容的聊天室

来自 , 2020-06-21, 写在 PHP, 查看 122 次.
URL http://www.code666.cn/view/f6c9dc70
  1. 使用方法:$s=make_password(长度);
  2. 如:$s=make_password(8); //将会随机生成一串8位数的字符串。
  3.  
  4. //取得随机数(混合),字母大小写加数字
  5. function make_password($pw_length){
  6.         $low_ascii_bound=50;
  7.         $upper_ascii_bound=122;
  8.         $notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
  9.         while($i<$pw_length)
  10.         {
  11.                 mt_srand((double)microtime()*1000000);
  12.                 $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  13.                 if(!in_array($randnum,$notuse))
  14.                 {
  15.                         $password1=$password1.chr($randnum);
  16.                         $i++;
  17.                 }
  18.         }
  19.         return $password1;
  20. }
  21.  
  22. //取得随机数(数字)
  23. function no_make_password($pw_length){
  24.         $low_ascii_bound=48;
  25.         $upper_ascii_bound=57;
  26.         $notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
  27.         while($i<$pw_length)
  28.         {
  29.                 mt_srand((double)microtime()*1000000);
  30.                 $randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
  31.                 if(!in_array($randnum,$notuse))
  32.                 {
  33.                         $password1=$password1.chr($randnum);
  34.                         $i++;
  35.                 }
  36.         }
  37.         return $password1;
  38. }

回复 "生成随机数(混合),字母大小写加数字,纯数字"

这儿你可以回复上面这条便签

captcha