zoukankan      html  css  js  c++  java
  • 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);
    }
    ?>

  • 相关阅读:
    qt映射器QSignalMapper的理解
    win10环境下安装Qt4.8、PyQt及development tools
    BZOJ1040 基环森林 找环+基础树形DP
    贪心 BZOJ1034
    HDU5293 树链剖分+树形DP
    BZOJ 1028 BZOJ 1029 //贪心
    BZOJ1025
    仙人掌图判定及求直径HDU3594 BZOJ1023
    BZOJ1021
    BZOJ1022
  • 原文地址:https://www.cnblogs.com/Mr-Wenyan/p/7273372.html
Copyright © 2011-2022 走看看