国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP通過GD庫實現(xiàn)驗證碼功能示例

2024-05-05 00:06:55
字體:
供稿:網(wǎng)友

本文實例講述了PHP通過GD庫實現(xiàn)驗證碼功能。分享給大家供大家參考,具體如下:

首先看看實現(xiàn)的效果:

PHP,GD庫,驗證碼

具體實現(xiàn):

<?php/*PHP實現(xiàn)驗證碼*/session_start();//開啟會話//創(chuàng)建畫布$image=imagecreatetruecolor(100,38);//背景顏色$bgcolor=imagecolorallocate($image,255,255,255);imagefill($image,0,0,$bgcolor);$captch_code='';//存儲驗證碼//隨機(jī)選取4個數(shù)字for($i=0;$i<4;$i++){  $fontsize=10;    //  $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//隨機(jī)顏色  $fontcontent=rand(0,9);  $captch_code.=$fontcontent;  $x=($i*100/4)+rand(5,10);  //隨機(jī)坐標(biāo)  $y=rand(5,10);  imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);}/*//字母和數(shù)字混合驗證碼for($i=0;$i<4;$i++) {  $fontsize = 10;    //  $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));//??????  $data = 'abcdefghijklmnopqrstuvwxyz1234567890';  //數(shù)據(jù)字典  $fontcontent = substr($data, rand(0, strlen($data)), 1);  $captch_code.=$fontcontent;  $x = ($i * 100 / 4) + rand(5, 10);  $y = rand(5, 10);  imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);}*/$_SESSION['code']=$captch_code;//增加干擾點for($i=0;$i<200;$i++){  $pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));  imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);//}//增加干擾線for($i=0;$i<3;$i++){  $linecolor=imagecolorallocate($image,rand(80,280),rand(80,220),rand(80,220));  imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);}//輸出格式header('content-type:image.png');imagepng($image);//銷毀圖片imagedestroy($image);

實現(xiàn)表單的連接和“換一個”功能的實現(xiàn):

<input type="text" placeholder="驗證碼" name="verifycode" class="captcha"><br><br><img id="captcha_img" src="captcha.php?r=<?php echo rand();?>" alt="驗證碼"><label><a href="javascript:void(0)" rel="external nofollow" onclick="document.getElementById('captcha_img').src='captcha.php?r='+Math.random()">換一個</a> </label>

captcha.php后面加上一個隨機(jī)參數(shù)是為了實現(xiàn)換一個驗證碼的功能,,換一個功能通過簡單的js即可實現(xiàn)。如果沒有這個功能可以不用參數(shù)。

希望本文所述對大家PHP程序設(shè)計有所幫助。


注:相關(guān)教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 古田县| 泸西县| 渝中区| 东兴市| 定襄县| 利川市| 田东县| 河东区| 岫岩| 民权县| 太保市| 延川县| 迁西县| 赤峰市| 昌黎县| 绥宁县| 天台县| 贡山| 九龙城区| 阜新市| 尼木县| 额敏县| 荆州市| 广宁县| 晴隆县| 大城县| 万宁市| 临泽县| 永济市| 山西省| 楚雄市| 江永县| 鸡西市| 安国市| 汉沽区| 阿拉善右旗| 霍林郭勒市| 吉林省| 富裕县| 万载县| 禹州市|