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

浏览:2868 发布日期:2013/09/16 分类:功能实现 关键字: 验证码
验证码类,放到 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<38;$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 < $length; $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 下载:177 次 )

评论() 相关
后面还有条评论,点击查看>>