免费注册 查看新帖 |

Chinaunix

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

一个简单的php图形验证码生成程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-25 21:16 |只看该作者 |倒序浏览
一个简单的php图形验证码生成程序
  1. <?php
  2. /**
  3. *
  4. * @file imgvcode.php
  5. * @create date 2007-09-25
  6. * @copyright (c) 2005 - 2007 eifr.com
  7. * @license http://www.hzhuti.com/nokia/n97/
  8. * eifr is free software
  9. */
  10. session_start();
  11. // main
  12. $vcodes = '';
  13. //generate Number 4
  14. srand((double)microtime()*1000000);
  15. for($i=0;$i<4;$i++){
  16.     $vcodes.=rand(1,9);
  17. }
  18. $_SESSION['eifr_checkvcode'] = $vcodes;
  19. if(function_exists('imagecreate')){
  20.     //generate picture validation code
  21.     Header("Content-type: image/PNG");
  22.     $img = imagecreate(44,18);
  23.     $bg = ImageColorAllocate($img, 245,245,245);
  24.     imagefill($img,0,0,$bg); //background
  25.    
  26.     //generate Number 4
  27.     for($i=0;$i<4;$i++){
  28.         $font = ImageColorAllocate($img, rand(100,255),rand(0,100),rand(100,255));
  29.         $vnum = substr($vcodes, $i, 1);
  30.         imagestring($img, 5, 2+$i*10, 1, $vnum, $font);
  31.     }
  32.     //add interference
  33.     for($i=0;$i<100;$i++)
  34.     {
  35.         $randcolor = ImageColorallocate($img,rand(0,255),rand(0,255),rand(0,255));
  36.         imagesetpixel($img, rand()%70 , rand()%30 , $randcolor);
  37.     }
  38.     ImagePNG($img);
  39.     ImageDestroy($img);
  40. }
  41. ?>
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-02-25 21:16 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP