Chinaunix首页 | 论坛 | 博客
  • 博客访问: 617044
  • 博文数量: 73
  • 博客积分: 1813
  • 博客等级: 上尉
  • 技术积分: 1213
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-27 19:59
文章分类
文章存档

2013年(1)

2012年(12)

2011年(28)

2010年(31)

2009年(1)

我的朋友

分类: 系统运维

2011-09-02 16:02:13

需要安装的库文件:
gd-2.0.33-9.4.el5_1.1
php-gd-5.1.6-23.el5  这个经常忘
gd-devel-2.0.33-9.4.el5_1.1
freetype-devel-2.2.1-19.el5
freetype-2.2.1-19.el5


下面是一个动态验证码的php文件:

点击(此处)折叠或打开

  1. <?php
  2. Header("Content-type: image/PNG");
  3. //采用session的方式传递
  4. session_start();
  5. $_SESSION['check_pic']='';

  6. //生成画布
  7. $im = @imagecreatetruecolor(60,20) or die('create error');

  8. $black = ImageColorAllocate($im, 0,0,0);
  9. $white = ImageColorAllocate($im, 255,255,255);
  10. $gray = ImageColorAllocate($im, 200,200,200);
  11. //生成验证码数字
  12. $check_num = rand(1000,9999);
  13. $_SESSION['check_pic']=$check_num;

  14. imagefill($im,0,0,$gray);
  15. $text_color = imagecolorallocate($im, 0, 0, 255);
  16. imagestring($im, 5, 10, 2, $check_num, $text_color);
  17. //增加干扰点
  18. for($i=0;$i<255;$i++){
  19.         $randcolor = ImageColorAllocate($im,rand(0,255),rand(0,255),rand(0,255));
  20.         imagesetpixel($im, rand(0,$i), rand(0,$i), $randcolor);
  21. }

  22. imagepng($im);
  23. imagedestroy($im);
  24. ?>
显示php验证码:

点击(此处)折叠或打开

  1. <td><img src='../checkcode.php' align='absmiddle'>
  2. <input type='text' size=5 name='typecode'></td>

阅读(1115) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~