這是利用GD庫(kù)生成驗(yàn)證碼的頁(yè)面
test.PHP
<?php header('Content-Type:image/jpeg'); $img = imagecreatetruecolor(100, 40); $black = imagecolorallocate($img, 0x00, 0x00, 0x00); $green = imagecolorallocate($img, 0x00, 0xFF, 0x00); $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF); imagefill($img,0,0,$white); //生成隨機(jī)的驗(yàn)證碼 $code = ''; for($i = 0; $i < 4; $i++) { $code .= rand(0, 9); } imagestring($img, 5, 10, 10, $code, $black); //加入噪點(diǎn)干擾 for($i=0;$i<50;$i++) { imagesetpixel($img, rand(0, 100) , rand(0, 100) , $black); imagesetpixel($img, rand(0, 100) , rand(0, 100) , $green); } //輸出驗(yàn)證碼 header("content-type: image/png"); imagepng($img); imagedestroy($img); ?>
這是點(diǎn)擊驗(yàn)證碼或看不清之后可實(shí)現(xiàn)局部刷新驗(yàn)證碼
test2.php
<script type="text/javascript"> function shuaxin() { document.getElementById('code').src = "test.php?"+Math.random(); } </script> <input type="text"><br /> <img id="code" src="test.php" onclick="shuaxin()" /> <span onclick="shuaxin()">看不清?</span><br />
如下圖所示:
總結(jié)
以上所述是小編給大家介紹的PHP使用GD庫(kù)制作驗(yàn)證碼的方法(點(diǎn)擊驗(yàn)證碼或看不清會(huì)刷新驗(yàn)證碼),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)網(wǎng)站的支持!
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。