• PHP生成随机验证码函数


    /*
    php生成验证码
    */

    <?php
    getCode(200,100);

    function getCode($width,$height){
    //$width---验证码图片的宽
    //$height---验证码图片高
      $img=imagecreatetruecolor($width,$height);

      $black=imagecolorallocate($img,0,0,0);
      $white=imagecolorallocate($img,255,255,255);
      $blue=imagecolorallocate($img,0,0,255);
      $red=imagecolorallocate($img,255,0,0);
      $yellow=imagecolorallocate($img,255,255,0);
      $green=imagecolorallocate($img,0,255,0);
      imagefill($img,0,0,$white);

      for($i==0;$i<5;$i++)
      {
        imageline($img,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,
        $width),mt_rand(0,$height),$blue);
        imageline($img,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,
        $width),mt_rand(0,$height),$red);
        img_linethick($img,$yellow,$width,$height);
        img_linethick($img,$green,$width,$height);

      }

      for($i==0;$i<30;$i++)
      {
        imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$black);
        imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$red);
        imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$blue);
        imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$yellow);
        imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$green);
      }

      shuffle($arr=array_rand(array_flip(array_merge(range(a,z),range(0,9),range (A,Z))),4));
      imagestring($img,5,($width/3),($height/2),implode(' ',$arr),$green);
      header("content-type:image/png");
      imagepng($img);
      imagedestroy($img);
    }


    function img_linethick($img,$color,$width,$height)
    {
    //$img---画布资源
    //$color---线条颜色
    //$width---验证码宽
    //$height---验证码高
      $ygomx1=mt_rand(4,$width);
      $ygomy1=mt_rand(4,$height);
      $ygomx11=$ygomx1;
      $ygomy11=$ygomy1+2;
      $ygomx2=mt_rand(4,$width);
      $ygomy2=mt_rand(4,$height);
      $ygomx22=$ygomx2;
      $ygomy22=$ygomy2+2;
      $point=array(
      $ygomx1,$ygomy1,
      $ygomx11,$ygomy11,
      $ygomx2,$ygomy2,
      $ygomx22,$ygomy22);
      imagefilledpolygon($img,$point,4,$color);
    }
    ?>

  • 相关阅读:
    如何实现文字两端对齐?
    三目运算符的复杂运算(条件嵌套判断)
    微信小程序实现图片上传,预览,删除
    微信小程序滚动条返回顶部
    vue+axios下载文件的实现
    java script 运算符
    关于placeholder提示内容出现在textarea底部问题
    js基础知识
    java script 字符串
    java script 函数
  • 原文地址:https://www.cnblogs.com/Mr-Wenyan/p/7273372.html
Copyright © 2020-2023  润新知