php生成图片验证码的方法__第1页
php生成图片验证码的方法__第2页
php生成图片验证码的方法__第3页
php生成图片验证码的方法__第4页
php生成图片验证码的方法__第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、php生成图片验证码的方法_ 本文为大家分享了php生成图片验证码的方法,供大家参考,具体内容如下 首先从指定字符集合中随机抽取固定数目的字符,以一种不规章的方法画在画布上,再适当添加一些干扰点和干扰元素,最终将图片输出,一张崭新的验证码就完成了。 前端代码如下: !DOCTYPE html html head meta http-equiv=content-type content=text/html;charset=utf-8 titleThis is a test!/title link rel=stylesheet type=text/css href=css/bootstrap.mi

2、n.css /head body form name=form input type=text placeholder=账号/br/ input type=password placeholder=密码/br/ input type=text placeholder=验证码/ img id=verImg src=libs/verification.php/ a href=# class=change onclick=changeVer()点击刷新/abr/ input type=submit value=登录/ /form script type=text/javascript /刷新验证码

3、function changeVer() document.getElementById(verImg).src=libs/verification.php?tmp=+Math.random(); /script /body /html php脚本文件验证码的代码如下: ?php session_start(); /开启session记录验证码数据 vCode(4, 15);/设置验证码的字符个数和图片基础宽度 /vCode 字符数目,字体大小,图片宽度、高度 function vCode($num = 4, $size = 20, $width = 0, $height = 0) !$wid

4、th $width = $num * $size * 4 / 5 + 15; !$height $height = $size + 10; /设置验证码字符集合 $str = 23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW; /保存猎取的验证码 $code = ; /随机选取字符 for ($i = 0; $i $num; $i+) $code .= $strmt_rand(0, strlen($str)-1); /创建验证码画布 $im = imagecreatetruecolor($width, $height); /背景色 $

5、back_color = imagecolorallocate($im, mt_rand(0,100),mt_rand(0,100), mt_rand(0,100); /文本色 $text_color = imagecolorallocate($im, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255); imagefilledrectangle($im, 0, 0, $width, $height, $back_color); / 画干扰线 for($i = 0;$i 5;$i+) $font_color = imagecolora

6、llocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255); imagearc($im, mt_rand(- $width, $width), mt_rand(- $height, $height), mt_rand(30, $width * 2), mt_rand(20, $height * 2), mt_rand(0, 360), mt_rand(0, 360), $font_color); / 画干扰点 for($i = 0;$i 50;$i+) $font_color = imagecolorallocate($im,

7、mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255); imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $font_color); /随机旋转角度数组 $array=array(5,4,3,2,1,0,-1,-2,-3,-4,-5); / 输出验证码 / imagefttext(image, size, angle, x, y, color, fontfile, text) imagefttext($im, $size , array_rand($array), 12, $size + 6, $text_color, c:WINDOWSFontssimsun.ttc, $code); $_SESSIONVerifyCode=$code; /no-cache在每次恳求时都会访问服务器 /max-age在恳求1s后再次恳求会再次访问服务器,must-revalidate则第一发送恳求会访问服务器,之后不会再访问服务器 / header(Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate); header(Cache-Control: no-cache); header(Content-type

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论