基本信息
源码名称:php 图片验证码 实例源码(随机)
源码大小:1.89KB
文件格式:.php
开发语言:PHP
更新时间:2017-02-10
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

随机生成验证码,防止暴力注册,函数封装,图片验证码里面的字符由$_SESSION传递


$element=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N',
                'O','P','Q','R','S','T','U','V','W','X','Y','Z',
                'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
                'o','p','q','r','s','t','u','v','w','x','y','z',
                '0','1','2','3','4','5','6','7','8','9');
$string='';
for($i=0;$i<5;$i ){
    $string.=$element[rand(0,count($element)-1)];
}
$img=imagecreatetruecolor($width,$height);
$color_bg=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));//分配颜色
$color_border=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));//分配颜色
$color_string=imagecolorallocate($img,rand(10,100),rand(10,100),rand(10,100));//分配颜色
imagefill($img,0,0,$color_bg);

imagerectangle($img,0,0,$width-1,$height-1,$color_border);
for($i=0;$i<100;$i ){
    imagesetpixel($img,rand(0,$width-1),rand(0,$height-1),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));
}
for($i=0;$i<3;$i ){
    imageline($img,rand(0,$width/2),rand(0,$height),rand($width/2,$width),rand(0,$height),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));
}
imagettftext($img,20,rand(-8,8),rand(5,15),rand(28,$height-5),$color_string,"font/consola.ttf",$string);
imagejpeg($img);
imagedestroy($img);