php 验证码
来源:互联网 发布:php rides 缓存 编辑:程序博客网 时间:2024/06/07 08:40
<?php /***获取验证码字符串*$str 字符串*$len 长度*$type 类型 1,数字 2,字母 3,混合*/function getVStr(&$str,$len=4,$type=1){ $num=range(0,9); $zm=range('a','z'); $str='';for ($i=0; $i < $len; $i++) { switch ($type) {case 1:$str.=$num[mt_rand(1,8)];break;case 2:$str.=$zm[mt_rand(0,25)];break;case 3:$ind=mt_rand(0,1);$str.=$ind?$zm[mt_rand(0,25)]:$num[mt_rand(1,8)];break;}}}/***生成验证码图片*$width 图片宽度*$height 图片高度*$len 长度*$type 类型 1,数字 2,字母 3,混合*$px 干扰点数目*$line 干扰线数目*/function proV($width=300, $height=30,$len=4,$type=1,$px=300,$line=5){$img=imagecreatetruecolor($width, $height);$bg=imagecolorallocate($img, 250, 250, 250);imagefilledrectangle($img, 0, 0, $width-1, $height-1, $bg);getVStr($str,$len,$type);$strArr=str_split($str,1);$fontfile='./arial.ttf';//字体文件//验证码内容foreach ($strArr as $i => $v) {$x=$i*($width/$len)+5;$y=mt_rand(30,35);$fg=imagecolorallocate($img, mt_rand(0,120), mt_rand(0,120), mt_rand(0,120));$angle=mt_rand(-30,30);imagettftext($img, 20, $angle, $x, $y, $fg, $fontfile, $v);// imagestring($img, 10, $x, $y, $v, $fg);}//干扰点for ($i=0; $i < $px; $i++) { $color=imagecolorallocate($img, mt_rand(60,200), mt_rand(60,200), mt_rand(60,200));imagesetpixel($img, mt_rand(0,$width-1), mt_rand(0,$height-1), $color);}//干扰线for ($i=0; $i < $line; $i++) { $color=imagecolorallocate($img, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));imageline($img, mt_rand(0,$width-1), mt_rand(0,$height-1), mt_rand(0,$width-1), mt_rand(0,$height-1), $color);}//把验证码信息保存到session中$_SESSION['l2js_yb_vf']=$str;//输出图片header("content-type:image/jpeg");imagejpeg($img);imagedestroy($img);}proV(170,42,5,3); ?>
0 0
- php图形验证码
- php 验证码
- PHP 验证码
- PHP图片验证码
- php验证码类
- php实现验证码
- PHP实现验证码
- PHP实现验证码
- PHP生成验证码
- PHP验证码
- php验证码类
- PHP 生成验证码
- php 验证码
- php 图片验证码
- php 验证码控件
- php 验证码总结
- PHP验证码生成
- PHP生成验证码
- C++中的继承与多态
- OpenCV直方图计算匹配方法详解calcHist
- 第11周-继承与派生-项目3-职员有薪水啦
- 15第十一周项目三——点类派生直线类
- gem install rails 安装失败
- php 验证码
- linux应用开发-内存共享
- matlabt若干舍入方法的介绍
- 【几何】[CQOI]RGB
- SQLServerToSQLite 程序代码的分析翻译及学习(二、根据数据库描述对象创建SQLite数据库)
- 可变参数列表(求平均数,找最大数)
- eclipse离线安装Android ADT 插件
- 合并JS和CSS
- ubuntu 14.04 安装 beyond compare