PHP 随机生成字符串,验证码,礼包码等
程序员文章站
2022-07-14 19:49:16
...
PHP 随机生成字符串,验证码,礼包码等
可调整生成个数和位数
$result=sp_gm_get_gift_code(1000);//随机生成1000个
foreach($result as $key => $value){
echo $value;
echo "<br>";
}
function sp_gm_get_gift_code($number) {
for ($i=0;$i<$number;$i++){
$uniqid = uniqid('gm',true);
$param_string = $_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR'].$_SERVER['SERVER_SOFTWARE'].time().rand().$uniqid;
$sha1 = sha1($param_string);
for(
$a=$sha1,
$s = '0123456789abcdefghijklmnopqrstuvwxyz',
$d = '',
$f = 0;
$f < 7;
$g = ord( $a[ $f ] ),
$d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],
$f++
);
yield $d;
}
}
上一篇: 深入理解Handler、Looper、Messagequeue
下一篇: R-基本数据类型