php实现完整版验证码(数字+大小写字母+干扰素)
2016-03-19 08:30
766 查看
在上一次简单的数字验证码之后,完善了验证码,使其更加具有使用价值,故将源码分享给大家,欢迎交流。
<?php //定义图像类型 header("Content-type:image/png"); //定义画布大小,即验证码区域 $img=imagecreatetruecolor(80, 25); //定义画笔颜色 $red1=imagecolorallocate($img, 0xff, 0x00, 0x00); $green1=imagecolorallocate($img, 0x00, 0xff, 0x00); $blue1=imagecolorallocate($img, 0x00, 0x00, 0xff); //定义画布背景色 $bgcolor=imagecolorallocate($img, 0xff, 0xff, 0xff); //将定义的颜色存入数组,以便随机换颜色 $col = array('0' =>$red1,'1'=>$green1,'2'=>$blue1 ); //填充画布背景色 imagefill($img, 0, 0, $bgcolor); //添加验证码内容 //内容定义 $content = "0123456789abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ; //随机内容确定 for($i=0;$i<4;$i++) { $code.=''; $code=$code.$content[rand(0,62)]; } //输出验证码 for($num=0;$num<4;$num++) { imagettftext($img, 15, rand(-30,30), 6+$num*18, 20, $col[rand(0,2)], "arial.ttf", $code[$num]); //该函数原型:imagettftext(image, size, angle, x, y, color, fontfile, text); } //添加干扰因素 //添加干扰点 for($i=0;$i<150;$i++) { imagesetpixel($img, rand(0,80), rand(0,40), $col[rand(0,2)]); } //添加干扰线 for($i=0;$i<4;$i++) { imageline($img, rand(0,20), rand(0,20), rand(0,80), rand(0,30), $col[rand(0,2)]); } //输出图像 imagepng($img); //释放图像资源 imagedestroy($img); ?>
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- java自动生成验证码插件-kaptcha
- 使用 Libki 来管理公共用户访问计算机
- PHP数据库长连接mysql_pconnect的细节
- 微型计算机的始祖:Altair 8800
- Php Installing An Expansion
- 通过手机、电脑远程开关机,Windows和linux机手机,电脑相互控制
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- 如何识别高级的验证码的技术总结第1/4页
- PHP 5.3.0 安装分析心得