欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
        }
    }