php 生成验证码程序
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-20 09:52:52 浏览: 评论:0
- <?php
- $consts = 'bcdfghjkmnpqrstwxyz';
- $vowels = 'aei23456789';
- for ($x = 0; $x < 6; $x++)
- {
- $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1);
- $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1);
- }
- $radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
- $_SESSION['checkcode'] = $string = substr($radomstring,0,4); //only display 4 str
- / t up image, the first number is the width and the second is the height
- $imageX = strlen($radomstring)*5.5; //the image width
- $imageY = 20; //the image height
- $im = imagecreatetruecolor($imageX,$imageY);
- //creates two variables to store color
- $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
- $foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
- imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
- imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
- imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)));
- $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80);
- $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
- $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80);
- //fill image with bgcolor
- imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
- //writes string
- imagestring($im, 5, 3, floor(rand(0,5))-1, $string[0], $foregroundArr[rand(0,3)]);
- imagestring($im, 5, 13, floor(rand(0,5))-1, $string[1], $foregroundArr[rand(0,3)]);
- imagestring($im, 5, 23, floor(rand(0,5))-1, $string[2], $foregroundArr[rand(0,3)]);
- imagestring($im, 5, 33, floor(rand(0,5))-1, $string[3], $foregroundArr[rand(0,3)]);
- for($i=0; $i<strlen($string); $i++)
- {
- if(mt_rand(0,ord(substr($string,$i,1)))%2 == 0)
- {
- $string{$i} = ' ';
- }
- }
- imagestring($im, 2, 2, 0, $string, $foreground2);
- //strikethrough
- $border = imagecolorallocate($im, 133, 153, 193);
- //imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back);
- imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);
- $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
- for ($i=0;$i<20;$i++)
- {
- imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
- }
- //rotate
- $middleground = imagecolorallocatealpha($im, rand(160, 200), rand(160, 200), rand(160, 200), 80);
- //random shapes
- for ($x=0; $x<15;$x++)
- {
- if(mt_rand(0,$x)%2==0)
- {
- imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
- imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
- }
- else
- {
- imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
- imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
- }
- }//开源代码phpfensi.com
- //output to browser
- header("content-type:image/png\r\n");
- imagepng($im);
- imagedestroy($im);
- ?>
Tags: php生成验证码 php验证码程序
- 上一篇:php 验证码图片程序
- 下一篇:php 图片中文验证码
相关文章
- ·PHP生成GIF动态图片验证码(2014-08-18)
- ·php生成验证码图片学习笔记(2014-08-19)
- ·php生成验证码类代码(2014-08-19)
- ·php生成验证码实现代码(2014-08-19)
- ·php生成验证码详细教程(2014-08-19)
- ·php加入干扰的生成验证码代码(2014-08-19)
- ·php生成图形验证码(2014-08-19)
- ·php 复杂生成验证码图片(2014-08-19)
- ·PHP生成带背景的图形验证码程序(2014-08-22)
- ·php生成验证码图片程序(2014-08-23)
- ·PHP验证码生成类完整代码(2014-08-28)
- ·php生成数字字母的验证码图片(2021-06-12)
- ·php生成验证码,缩略图及水印图的类分享(2021-07-27)
- ·php 验证码图片程序(2014-08-20)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)