免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2317 | 回复: 0
打印 上一主题 下一主题

php验证码之数字运算验证码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-07-30 09:27 |只看该作者 |倒序浏览
php验证码之数字运算验证码,继续上一篇的数字验证码。
math.php
  1. <?php
  2. getValidate(100,30);

  3. function getValidate($w,$h){
  4.     $img = imagecreate($w,$h);

  5.     $gray = imagecolorallocate($img,255,255,255);
  6.     $black = imagecolorallocate($img,rand(0,200),rand(0,200),rand(0,200));
  7.     $red = imagecolorallocate($img, 255, 0, 0);
  8.     $white = imagecolorallocate($img, 255, 255, 255);
  9.     $green = imagecolorallocate($img, 0, 255, 0);
  10.     $blue = imagecolorallocate($img, 0, 0, 255);
  11.     imagefilledrectangle($img, 0, 0, 100, 30, $black);


  12.     for($i = 0;$i < 80;$i++){
  13.         imagesetpixel($img, rand(0,$w), rand(0,$h), $gray);
  14.     }


  15.     $num1 = rand(1,99);
  16.     $num2 = rand(1,99);

  17.     imagestring($img, 5, 5, rand(1,10), $num1, $red);
  18.     imagestring($img,5,30,rand(1,10),getRand(), $white);
  19.     imagestring($img,5,45,rand(1,10),$num2, $green);
  20.     imagestring($img,5,65,rand(1,10),"=", $blue);
  21.     imagestring($img,5,80,rand(1,10),"?", $red);
  22.      

  23.     header("content-type:image/png");
  24.     imagepng($img);
  25.     imagedestroy($img);
  26. }
  27. function getRand(){
  28.     $code = rand(0,1);
  29.     switch ($code) {
  30.         case 0:
  31.             return "+";
  32.             break;
  33.         case 1:
  34.             return "-";
  35.             break;
  36.         default:
  37.             # code...
  38.             break;
  39.     }
  40. }

  41. ?>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP