PHP七种不同的个性创意验证码

PHP七种不同的个性创意验证码

本demo的验证码共7种,验证方法就不写了,原理就是看用户输入的验证码和当前的session code进行对比,若是一致,说明正确,否则失败。具体PHP验证码验证方法,请看http://www.sucaiq.com/jquery/5/533/demo/

淘建站为您提供更多_插件_验证码_code,在此特别感谢您对我们的支持与厚爱!

查看演示

演示不了,点击反馈

加入收藏

下载 139 次

打赏作者

觉得不错,可打赏下作者

下载资源

免费共享

特别说明:本站资源来自网友发布分享,仅供学习与参考,请勿用于商业用途,若有侵权请联系删除(272966172@qq.com)。
分类:PHP功能模块 > 插件 难易程度:初级

验证码图片html代码

<img src="1.php" onclick="this.src = '1.php?t=' + Math.random()" title="点击刷新" />

第一个图像验证码类,其他6种验证码类请下载查看

class captcha{
    /**
    +----------------------------------------------------------
    * 生成验证码
    +----------------------------------------------------------
    * @static
    * @access public
    +----------------------------------------------------------
    * @param int $len  验证码字符数
    * @param int $font_size  验证码字体大小
    * @param string $name  session名称
    * @param int $width  图片长度
    * @param int $height  图片高度
      +----------------------------------------------------------
    * @return void
      +----------------------------------------------------------
    */
    static function generate($len=4,$font_size=48,$name='captcha',$width='',$height=''){
        if($width=='') $width=($font_size+5)*($len+1);
        if($height=='') $height=($font_size)*2;
        $chars='bcdefhkmnrstuvwxyABCDEFGHKMNPRSTUVWXY345689';
        $str='';
        for($i=0;$i<$len;$i++){
            $str .= substr($chars,mt_rand(0,strlen($chars)-1),1);
        }
        $_SESSION[$name]=$str;//写入session
        for($num=0;$num<10;$num++){
            ob_start();
            $image=imagecreatetruecolor($width,$height);//创建图片
            $bg_color=imagecolorallocate($image,255,255,255);//设置背景颜色
            $border_color=imagecolorallocate($image,100,100,100);//设置边框颜色
            $text_color=imagecolorallocate($image,0,0,0);//设置验证码颜色
            imagefilledrectangle($image,0,0,$width-1,$height-1,$bg_color);//填充图片背景色
            imagerectangle($image,0,0,$width-1,$height-1,$border_color);//填充图片边框颜色
            for($i=0;$i<5;$i++){
                $line_color=imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255));//干扰线颜色
                imageline($image,rand(0,$width),0,$width,$height,$line_color);//画一条线段
            }
            for($i=0;$i<500;$i++){
                $dot_color=imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255));//干扰点颜色
                imagesetpixel($image,rand()%$width,rand()%$height,$dot_color);//画一个像素点
            }
            for($i=0;$i<$len;$i++){
                imagettftext($image,$font_size,rand(-3,3),$font_size/2+($font_size+5)*$i,$height/1.25-rand(2,3),$text_color,'Groupsex.ttf',$str[$i]);//用规定字体向图像写入文本
            }
            imagegif($image);
            imagedestroy($image);
            $imagedata[] = ob_get_contents();
            ob_clean();
        }
        require('GIFEncoder.class.php');
        $gif = new GIFEncoder($imagedata);
        ob_clean();//防止出现'图像因其本身有错无法显示'的问题
        header('Content-type:image/gif');
        echo $gif->GetAnimation();
    }
}
//调用示例
session_start();
captcha::generate(6,48);

声明:本资料由淘建站会员提供,如转载注明来源,资料来源淘建站免费素材库:https://www.taojz.cn/mokuai/721.html
PHP七种不同的个性创意验证码 希望对你有帮助,感谢您的支持!
留言(0)
头像
 阿里云限量代金券,戳我领取
1 2