Heim > Backend-Entwicklung > PHP-Tutorial > php 实现验证码制作,php实现验证码_PHP教程

php 实现验证码制作,php实现验证码_PHP教程

WBOY
Freigeben: 2016-07-13 09:51:30
Original
933 Leute haben es durchsucht

php 实现验证码制作,php实现验证码

先给看下 大致的效果

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

<?<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><4;<span>$i</span>++ ){                  <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><200;<span>$i</span>++ ){              <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><3;<span>$i</span>++){                <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>?>
Nach dem Login kopieren

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1012939.htmlTechArticlephp 实现验证码制作,php实现验证码 先给看下 大致的效果 那么接下来的就直接贴代码吧 ? php $image = imagecreatetruecolor(100, 30); // 创建画布 $i...
Verwandte Etiketten:
php
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage