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

首頁 > 語言 > PHP > 正文

php實現網頁端驗證碼功能

2024-05-04 23:58:42
字體:
來源:轉載
供稿:網友

我們在實際開發中,會用到短信驗證碼以及網頁驗證碼,相對來說網頁驗證碼的成本比較低,安全系數也還可以,接下來我們就來做一個網頁端的驗證碼,直接上代碼:

首先來說一下文件目錄結構:

    |----------phpyanzheng  項目文件夾

      |----fonttype 文件夾放字體文件,字體文件一般以 .ttf和.otf結尾

      |----1.php  里面放php語言代碼

      |----index.html  里面放網頁布局

1.php

<?php  header('content-type:image/jpeg');//定義一下代碼以jpeg文件來解析  $width = 120;//定義了圖像的寬  $height = 40;//定義了圖像的高  $element = array('q','w','e','r','t','y','u','i','o','p','l','k','j','h','g','f','d','s','a','z','x',  'c','v','b','n','m','1','2','3','4','5','6','7','8','9','0','Q','W','E','R','T','Y','U','I','O','P','A'  ,'S','D','F','G','H','J','K','L','M','N','B','V','C','X','Z');//定義一個顯示文本的數組  $string = '';  for($i=0;$i<4;$i++){    $string.=$element[rand(0,count($element)-1)];//隨機產生四個文本目標  }  $img = imagecreatetruecolor($width, $height);//設置驗證區寬高  $colorBg = imagecolorallocate($img,rand(185,255),rand(185,255),rand(185,255));//產生200-255的隨機數  $colorBorder = imagecolorallocate($img,rand(50,100),rand(50,100),rand(50,100));//邊框顏色  $colorDian = imagecolorallocate($img,rand(0,100),rand(0,100),rand(0,100));//背景小點的顏色  $colorLine = imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));  $colorString = imagecolorallocate($img,rand(20,80),rand(20,80),rand(20,80));  imagefill($img, 0, 0, $colorBg);//設置位置和背景顏色  imagerectangle($img,0,0,$width-1,$height-1,$colorBorder);//畫一個邊框  for($i=0;$i<200;$i++){//循環出200個干擾點    imagesetpixel($img, rand(0, $width-1), rand(0, $height-1), $colorDian);  }  for($i=0;$i<round(5);$i++){//循環出5條干擾線    imageline($img,rand(0,$width/2),rand(0,$height/2),rand($width/2,$width),rand($height/2,$height),$colorLine);  }  //imagestring($img, 4, 0, 0,'a5dg', $colorString);    imagettftext($img,25,rand(5, 15),rand(0,40),39,$colorString,'fonttype/PrincetownStd.otf',$string);  //    圖像名稱  字體大小 傾斜角度 起始位置X軸 起始位置Y軸 顏色 字體位置 顯示的內容  imagejpeg($img);//輸出圖像?>

index.html

<!DOCTYPE html><html>  <head>    <meta charset="UTF-8">    <title>孫三峰--驗證碼</title>    <script type="text/javascript" src="js/jquery-1.1.0.js" ></script>  </head>  <body>    <!--注意:原文中對應的ip地址是自己電腦端ip,如果不能正常運行,請修改ip-->    <p>      <label class="lbright">驗證碼:</label>       <span>         <input type="text" name="validcode" style="width:70px; vertical-align:middle;" id="validcode"/>         <img id="codePic" src="http://192.168.1.113:8601/PHP/phpyanzheng/1.php" width="120" height="40"/>                </span>               <span id="codePic" onclick="getPic();">看不清楚,換一張</span> <!---->    </p>       </body>  <script type="text/javascript">      function getPic(){          $("#codePic").attr("src","http://192.168.1.113:8601/PHP/phpyanzheng/1.php?flag="+Math.random()); <!--局部刷新-->      };   </script></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


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

圖片精選

主站蜘蛛池模板: 外汇| 安达市| 富裕县| 孝义市| 古蔺县| 长阳| 区。| 闸北区| 甘泉县| 凌海市| 昌邑市| 安溪县| 锦屏县| 延边| 天峨县| 调兵山市| 皋兰县| 正阳县| 新建县| 林甸县| 津南区| 栖霞市| 莱西市| 阿鲁科尔沁旗| 闽清县| 淳安县| 西藏| 荆州市| 沐川县| 洛南县| 巴彦县| 溧水县| 涟水县| 清流县| 西乌| 桃园市| 青河县| 交口县| 崇明县| 昌邑市| 灵璧县|