欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

分享下 我网站注册时候的验证码

程序员文章站 2022-05-26 10:14:32
...
验证码类,放到 util 下的Images.class.php 里,字体见附件,或者改成你的,命名别重复
分享下 我网站注册时候的验证码static function buildImageVerify($length=4, $mode=1, $type='png', $width=80, $height=40, $verifyName='verify') {
import('ORG.Util.String');
$randval = String::randString($length, $mode);
$_SESSION[$verifyName] = md5($randval);
$width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;
if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
$im = imagecreatetruecolor($width, $height);
} else {
$im = imagecreate($width, $height);
}
$backColor = imagecolorallocate($im, 255, 255, 255);
imagefill($im,0,0,$backColor);
$borderColor = imagecolorallocate($im,200,200,200);
imagerectangle($im,0,0,79,39,$borderColor);

for($i=2;$i $line_color = imagecolorallocate($im,rand(200,255),rand(200,255),rand(200,255));
imageline($im,2,$i,77,$i,$line_color);
}
$pic=$im;
$fontfiles = THINK_PATH . 'Font/CORBELZ.TTF';
$font_size=10;
$Str[0] = "ABCDEFGHIJKLMNoPQRSTUVWXYZ";
$Str[1] = "abcdefghijklmnopqrstuvwxyz";
$Str[2] = "1234567890123456789ABCDEFG";

$imstr[0]["s"] = $Str[rand(0,2)][rand(0,25)];
$imstr[0]["x"] = rand(2,5);
$imstr[0]["y"] = rand(1,2);

$imstr[1]["s"] = $Str[rand(0,2)][rand(0,25)];

$imstr[1]["x"] = $imstr[0]["x"]+rand(10,22)-1+rand(0,1);
$imstr[1]["y"] = rand(1,3);


$imstr[2]["s"] = $Str[rand(0,2)][rand(0,25)];

$imstr[2]["x"] = $imstr[1]["x"]+rand(10,22)-1+rand(0,1);
$imstr[2]["y"] = rand(1,2);


$imstr[3]["s"] = $Str[rand(0,2)][rand(0,25)];
$imstr[3]["x"] = $imstr[2]["x"]+rand(10,22)-1+rand(0,1);
$imstr[3]["y"] = rand(1,3);

for ($i = 0; $i $text_color = imagecolorallocate($im,rand(1,255),rand(1,255),rand(1,255));
imagettftext($pic,rand(20,50),$imstr[3]["y"],$imstr[$i]["x"],rand(30,40),$text_color, $fontfiles, $randval{$i});
}
Image::output($im, $type);
}
演示地址 http://www.52zjk.cn/Index/reg

分享下 我网站注册时候的验证码 CORBELZ.rar ( 74 KB 下载:171 次 )

AD:真正免费,域名+虚机+企业邮箱=0元