Home >php教程 >php手册 >分享下 我网站注册时候的验证码

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

WBOY
WBOYOriginal
2016-06-07 11:43:551141browse

验证码类,放到 util 下的Images.class.php 里,字体见附件,或者改成你的,命名别重复
分享下 我网站注册时候的验证码static function buildImageVerify($length=4, $mode=1, $type='png', $width=80, $height=40, $verifyName='verify') {<br>         import('ORG.Util.String');<br>         $randval = String::randString($length, $mode);<br>         $_SESSION[$verifyName] = md5($randval);<br>         $width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;<br>         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {<br>             $im = imagecreatetruecolor($width, $height);<br>         } else {<br>             $im = imagecreate($width, $height);<br>         }<br>         $backColor = imagecolorallocate($im, 255, 255, 255); <br>         imagefill($im,0,0,$backColor); <br>         $borderColor = imagecolorallocate($im,200,200,200);  <br>         imagerectangle($im,0,0,79,39,$borderColor); <br> <br>         for($i=2;$i             $line_color = imagecolorallocate($im,rand(200,255),rand(200,255),rand(200,255)); <br>             imageline($im,2,$i,77,$i,$line_color); <br>         }<br>         $pic=$im;<br>         $fontfiles = THINK_PATH . 'Font/CORBELZ.TTF';<br>         $font_size=10;<br>         $Str[0] = "ABCDEFGHIJKLMNoPQRSTUVWXYZ";<br>         $Str[1] = "abcdefghijklmnopqrstuvwxyz";<br>         $Str[2] = "1234567890123456789ABCDEFG";<br>          <br>         $imstr[0]["s"] = $Str[rand(0,2)][rand(0,25)]; <br>         $imstr[0]["x"] = rand(2,5); <br>         $imstr[0]["y"] = rand(1,2); <br> <br>         $imstr[1]["s"] = $Str[rand(0,2)][rand(0,25)]; <br> <br>         $imstr[1]["x"] = $imstr[0]["x"]+rand(10,22)-1+rand(0,1); <br>         $imstr[1]["y"] = rand(1,3); <br> <br> <br>         $imstr[2]["s"] = $Str[rand(0,2)][rand(0,25)]; <br> <br>         $imstr[2]["x"] = $imstr[1]["x"]+rand(10,22)-1+rand(0,1); <br>         $imstr[2]["y"] = rand(1,2); <br> <br>          <br>         $imstr[3]["s"] = $Str[rand(0,2)][rand(0,25)]; <br>         $imstr[3]["x"] = $imstr[2]["x"]+rand(10,22)-1+rand(0,1); <br>         $imstr[3]["y"] = rand(1,3); <br> <br>         for ($i = 0; $i              $text_color = imagecolorallocate($im,rand(1,255),rand(1,255),rand(1,255)); <br>             imagettftext($pic,rand(20,50),$imstr[3]["y"],$imstr[$i]["x"],rand(30,40),$text_color, $fontfiles, $randval{$i}); <br>         }<br>         Image::output($im, $type);<br>     }演示地址 http://www.52zjk.cn/Index/reg

附件 CORBELZ.rar ( 74 KB 下载:171 次 )

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn