PHP 简单随机传递发生器

Posted

tags:

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

function gen_pass()
{
	// load up our valid character string
	$chars	=	'01234567890';
	$chars	.=	'abcdefghijklmnopqrstuvwxyz';
	$chars	.=	'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	$chars	.=	'~!@#$%^&*()_+{}[]|/?<>,.';

	// set password legnth between 8 and 14 characters long
	$len	= rand(8, 14);

	// initialize password & counter
	$pass	= '';
	$i		= 0;

	while ($i < $len)
	{
		// get a new character
		$new_char	= substr($chars, rand(0, strlen($chars) -1), 1);

		// ensure all characters are different
		if(! strstr($pass, $new_char))
		{
			$pass	.= $new_char;
			$i++;
		}
	}

	return $pass;
}

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

php 安全随机发生器

PHP 随机颜色发生器

PHP 随机数发生器

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

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

禅宗花园随机发生器