• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP生成随机验证码函数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

/*
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);
}
?>


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP递归实现层级树状展现数据发布时间:2022-07-10
下一篇:
在sql语句中添加php变量发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap