PHP 随机传递发生器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 随机传递发生器相关的知识,希望对你有一定的参考价值。

function generatePassword ($length = 8) {
  $password = "";
  $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-$!?]["; 
   
  $i = 0; 
  // add random characters to $password until $length is reached
  while ($i < $length) { 
    // pick a random character from the possible ones
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
    // we don't want this character if it's already in the password
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }
  }
  return $password;
}

以上是关于PHP 随机传递发生器的主要内容,如果未能解决你的问题,请参考以下文章

php 安全随机发生器

PHP 随机颜色发生器

PHP 随机数发生器

PHP 和 Sodium - 无法在表单中公开传递随机数

PHP中的几个随机数生成函数

禅宗花园随机发生器