《PHP實(shí)例:PHP使用GD庫(kù)制作驗(yàn)證碼的方法(點(diǎn)擊驗(yàn)證碼或看不清會(huì)刷新驗(yàn)證碼)》要點(diǎn):
本文介紹了PHP實(shí)例:PHP使用GD庫(kù)制作驗(yàn)證碼的方法(點(diǎn)擊驗(yàn)證碼或看不清會(huì)刷新驗(yàn)證碼),希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
這是利用GD庫(kù)生成驗(yàn)證碼的頁(yè)面PHP實(shí)例
test.PHPPHP實(shí)例
<?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)證碼PHP實(shí)例
test2.phpPHP實(shí)例
<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 />
如下圖所示:
PHP實(shí)例
PHP實(shí)例
總結(jié)PHP實(shí)例
以上所述是小編給大家介紹的PHP使用GD庫(kù)制作驗(yàn)證碼的方法(點(diǎn)擊驗(yàn)證碼或看不清會(huì)刷新驗(yàn)證碼),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的.在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!PHP實(shí)例
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/303.html