Rumah > pembangunan bahagian belakang > tutorial php > php生成验证码图片,_PHP教程

php生成验证码图片,_PHP教程

WBOY
Lepaskan: 2016-07-13 09:46:42
asal
780 orang telah melayarinya

php生成验证码图片,

<?<span>php

</span><span>header</span> ('Content-Type: image/png'<span>);
</span><span>$image</span>=imagecreatetruecolor(100, 30<span>);
</span><span>$color</span>=imagecolorallocate(<span>$image</span>, 255, 255, 255<span>);
imagefill(</span><span>$image</span>, 20, 20, <span>$color</span><span>);<br />//只含有数字
</span><span>//</span><span> for($i=0;$i<4;$i++){
    // $font=6;
    // $x=rand(5,10)+$i*100/4;
    // $y=rand(8, 15);
    // $string=rand(0, 9);
    // $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
    // imagestring($image, $font, $x, $y, $string, $color);
// }<br /><br /></span>//含有数字和字母的
<span>for</span>(<span>$i</span>=0;<span>$i</span><4;<span>$i</span>++<span>){
    </span><span>$fontSize</span>=6<span>;
    </span><span>$x</span>=<span>rand</span>(5,10)+<span>$i</span>*100/4<span>;
    </span><span>$y</span>=<span>rand</span>(5, 15<span>);
    </span><span>$data</span>='abcdefghijklmnopqrstuvwxyz123456789'<span>;
    </span><span>$string</span>=<span>substr</span>(<span>$data</span>,<span>rand</span>(0, <span>strlen</span>(<span>$data</span>)),1<span>);
    </span><span>$color</span>=imagecolorallocate(<span>$image</span>,<span>rand</span>(0,120), <span>rand</span>(0,120), <span>rand</span>(0,120<span>));
    imagestring(</span><span>$image</span>, <span>$fontSize</span>, <span>$x</span>, <span>$y</span>, <span>$string</span>, <span>$color</span><span>);
}<br />//干扰点元素
</span><span>for</span>(<span>$i</span>=0;<span>$i</span><200;<span>$i</span>++<span>){
    </span><span>$pointColor</span>=imagecolorallocate(<span>$image</span>, <span>rand</span>(100, 255), <span>rand</span>(100, 255), <span>rand</span>(100, 255<span>));
    imagesetpixel(</span><span>$image</span>, <span>rand</span>(0, 100), <span>rand</span>(0, 30), <span>$pointColor</span><span>);
}<br />//干扰线元素
</span><span>for</span>(<span>$i</span>=0;<span>$i</span><2;<span>$i</span>++<span>){
    </span><span>$linePoint</span>=imagecolorallocate(<span>$image</span>, <span>rand</span>(150, 255), <span>rand</span>(150, 255), <span>rand</span>(150, 255<span>));
    imageline(</span><span>$image</span>, <span>rand</span>(10, 50), <span>rand</span>(10, 20), <span>rand</span>(80,90), <span>rand</span>(15, 25), <span>$linePoint</span><span>);
}
imagepng(</span><span>$image</span><span>);
imagedestroy(</span><span>$image</span><span>);
</span>?>
Salin selepas log masuk

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1030386.htmlTechArticlephp生成验证码图片, ? php header ('Content-Type: image/png' ); $image =imagecreatetruecolor(100, 30 ); $color =imagecolorallocate( $image , 255, 255, 255 );imagefill( $imag...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan