php 实现验证码制作

WBOY
发布: 2016-08-08 09:22:58
原创
957 人浏览过

先给看下 大致的效果

那么接下来的就直接贴代码吧

<span>php
    
    </span><span>$image</span> = imagecreatetruecolor(100, 30); <span>//</span><span>创建画布</span><span>$imagecolor</span> = imagecolorallocate(<span>$image</span>, 255, 255, 255);  <span>//</span><span>背景色</span><span>
    imagefill(</span><span>$image</span>, 0, 0, <span>$imagecolor</span>);  <span>//</span><span>填充背景色</span><span>for</span>(<span>$i</span>=0;<span>$i</span>$i++ ){                  <span>//</span><span>循环4位数</span><span>$fontsize</span> = 6<span>;
        </span><span>$fontcolor</span> = imagecolorallocate(<span>$image</span>, <span>rand</span>(0, 200), <span>rand</span>(0, 200), <span>rand</span>(0, 200<span>));
        </span><span>$fontcontent</span> = <span>rand</span>(0, 9<span>);
        
        </span><span>$x</span> = <span>$i</span>*100/4 + <span>rand</span>(5, 15<span>);
        </span><span>$y</span> = <span>rand</span>(5, 10<span>);
        
        imagestring(</span><span>$image</span>, <span>$fontsize</span>, <span>$x</span>, <span>$y</span>, <span>$fontcontent</span>, <span>$fontcolor</span><span>);
    }
    
    
    
    </span><span>for</span>(<span>$i</span>=0;<span>$i</span>$i++ ){              <span>//</span><span>循环 添加干扰点</span><span>$pointcolor</span> = imagecolorallocate(<span>$image</span>, <span>rand</span>(50, 200), <span>rand</span>(50, 200), <span>rand</span>(50, 200<span>));
        
        </span><span>$x</span> = <span>rand</span>(1, 99<span>);
        </span><span>$y</span> = <span>rand</span>(1, 29<span>);
        
        imagesetpixel(</span><span>$image</span>, <span>$x</span>, <span>$y</span>, <span>$pointcolor</span><span>);
    }
    
    
    
    </span><span>for</span>(<span>$i</span>=0;<span>$i</span>$i++){                <span>//</span><span>循环 添加干扰线    </span><span>$linecolor</span> = imagecolorallocate(<span>$image</span>, <span>rand</span>(100, 250), <span>rand</span>(100, 250), <span>rand</span>(100, 250<span>));
        
        </span><span>$x1</span> = <span>rand</span>(1, 25<span>);
        </span><span>$x2</span> = <span>rand</span>(50, 75<span>);
        
        </span><span>$y1</span> = <span>rand</span>(1, 15<span>);
        </span><span>$y2</span> = <span>rand</span>(15, 25<span>);
        
        imageline(</span><span>$image</span>, <span>$x1</span>, <span>$y1</span>, <span>$x2</span>, <span>$y2</span>, <span>$linecolor</span><span>);
    }
    
    
    
    </span><span>header</span>("content-type:image/png"<span>);
    
    imagepng(</span><span>$image</span><span>);
    
    imagedestroy(</span><span>$image</span><span>);

</span>?>
登录后复制

以上就介绍了php 实现验证码制作,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板