需要安装的库文件:
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文件:
- <?php
- Header("Content-type: image/PNG");
- //采用session的方式传递
- session_start();
- $_SESSION['check_pic']='';
- //生成画布
- $im = @imagecreatetruecolor(60,20) or die('create error');
- $black = ImageColorAllocate($im, 0,0,0);
- $white = ImageColorAllocate($im, 255,255,255);
- $gray = ImageColorAllocate($im, 200,200,200);
- //生成验证码数字
- $check_num = rand(1000,9999);
- $_SESSION['check_pic']=$check_num;
- imagefill($im,0,0,$gray);
- $text_color = imagecolorallocate($im, 0, 0, 255);
- imagestring($im, 5, 10, 2, $check_num, $text_color);
- //增加干扰点
- for($i=0;$i<255;$i++){
- $randcolor = ImageColorAllocate($im,rand(0,255),rand(0,255),rand(0,255));
- imagesetpixel($im, rand(0,$i), rand(0,$i), $randcolor);
- }
- imagepng($im);
- imagedestroy($im);
- ?>
显示php验证码:
- <td><img src='../checkcode.php' align='absmiddle'>
- <input type='text' size=5 name='typecode'></td>
阅读(1192) | 评论(0) | 转发(0) |