php中驗(yàn)證碼圖片如何生成-創(chuàng)新互聯(lián)

這篇文章主要介紹了php中驗(yàn)證碼圖片如何生成,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比海勃灣網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式海勃灣網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋海勃灣地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。

1.驗(yàn)證碼圖片生成
captcha.php


//1.生成100*30大小的圖片,默認(rèn)為黑色
$image = imagecreatetruecolor(100,30);
//創(chuàng)建白色底圖
$bgcolor = imagecolorallocate($image,255,255,255);
//用白色填充黑色
imagefill ($image,0,0,$bgcolor);

//2.隨機(jī)顯示數(shù)字或字母
$captch_code = "";
for($i=0;$i<4;$i++){
 $fontsize=6;
 $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
 $data = "abcdefghijkmnpqrstuvwxy3456789";
 $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["authcode"] = $captch_code;

//3.增加干擾
//干擾點(diǎn)
for($i=0;$i<100;$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<2;$i++){
 $linecolor=imagecolorallocate($image,rand(80,220),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);

2.頁面實(shí)現(xiàn)驗(yàn)證碼功能
form.php


<?php
if(isset($_POST["authcode"])){
 session_start();
 if(strtolower($_POST["authcode"])==$_SESSION["authcode"]){
  echo "OK";
 }else{
  echo "NO";
 }
}

?>


<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
<form action="form.php" method="post">
 <p>驗(yàn)證碼圖片: <img id="img" border="1" src="captcha.php?r=<?php echo rand()?>" alt="">
 <a href="javascript:void(0)" onclick="document.getElementById('img').src='captcha.php?r'+Math.random() ">換一個(gè)</a>
 </p>
 <p><input type="text" name="authcode"></p>
 <p><input type="submit" value="提交"></p>

</form>
</body>
</html>

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“php中驗(yàn)證碼圖片如何生成”這篇文章對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!

分享文章:php中驗(yàn)證碼圖片如何生成-創(chuàng)新互聯(lián)
本文來源:http://muchs.cn/article40/coegeo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、手機(jī)網(wǎng)站建設(shè)、微信小程序、靜態(tài)網(wǎng)站自適應(yīng)網(wǎng)站品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站