码迷,mamicode.com
首页 > Web开发 > 详细

PHP 生成验证码 (二)

时间:2014-11-17 10:36:50      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   sp   for   div   

 1 <?php 
 2     //验证码制作
 3   
 4     session_start();
 5     //生成验证码图片
 6     Header("Content-type: image/PNG");
 7     $im = imagecreate(44,18); // 画一张指定宽高的图片
 8     $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
 9     imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
10     $vcodes = "";
11     srand((double)microtime()*1000000);
12     $srcstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 
13     //生成4位数字
14     for($i=0;$i<4;$i++) {
15         $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
16         $authnum = $srcstr[mt_rand(0,35)];
17         $vcodes.= $authnum;
18         imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
19     }
20     $_SESSION[‘VCODE‘] = $vcodes;
21 
22     for($i=0;$i<100;$i++) {//加入干扰象素   
23         $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
24         imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
25     }
26     ImagePNG($im);
27     ImageDestroy($im); 
28 ?> 

 

PHP 生成验证码 (二)

标签:des   style   blog   io   color   ar   sp   for   div   

原文地址:http://www.cnblogs.com/yll-sww/p/4103006.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!