日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHP驗證碼在驗證頁面中的應用分析

對于一個網(wǎng)站來說,肯定會需要一個提供驗證功能的頁面。那么我們現(xiàn)在就需要考慮驗證頁面中的驗證碼的應用了。我們接下來將要為大家具體講解有關PHP驗證碼的相關應用方法。

#t#一、準備一個展示并提交PHP驗證碼的頁面

 
 
 
  1.     
  2.     
  3.     @header("content-type:text/html; charset=UTF-8");     
  4.     
  5.     //打開session     
  6.     
  7.     session_start();     
  8.     
  9. ?>    
  10.     
  11.     
  12.     
  13.         
  14.     
  15.         http-equiv="Content-Type" content="text/html; charset=utf-8" />    
  16.     
  17.        </strong>PHP驗證碼示例<strong>    
  18.     
  19.         
  20.     
  21.         
  22.     
  23.        驗證碼:
        
  24.     
  25.         id="iimg" height="100" width=300 src="img.php" frameborder="0" >    
  26.     
  27.        
        
  28.     
  29.         type=button value="看不清,換一張" onclick="iimg.location.reload();">    
  30.     
  31.        
        
  32.     
  33.         action="validate.php" method="post">    
  34.     
  35.            輸入驗證碼: name="imgId" style="width:60">    
  36.     
  37.             type="submit" value="確定">    
  38.     
  39.            
  40.     
  41.         
  42.     
  43.    

二、以下是PHP驗證碼生成頁面,該頁面在***頁面中被調(diào)用

 
 
 
  1.     
  2.     
  3. Header("Content-type: image/gif");     
  4.     
  5. session_start();     
  6.     
  7. //驗證碼為隨機字符,以下是算法     
  8.     
  9. $randval;     
  10.     
  11. for($i=0;$i<7;$i++){     
  12.     
  13.     $randstr = mt_rand(ord('A'),ord('Z'));     
  14.     
  15.     srand((double)microtime()*1000000);     
  16.     
  17.     $randv = mt_rand(0,10);     
  18.     
  19.     if($randv%2==0){     
  20.     
  21.        $randval.=mt_rand(0,10);     
  22.     
  23.     }else{     
  24.     
  25.        $randval.=chr($randstr);     
  26.     
  27.     }     
  28.     
  29. }     
  30.     
  31. //注冊PHP驗證碼到session     
  32.     
  33. session_register($randval);     
  34.     
  35. //以下是繪制驗證碼圖     
  36.     
  37. $height = 50;//圖高     
  38.     
  39. $width = 100;//圖寬     
  40.     
  41. $im = ImageCreateTrueColor($width, $height);     
  42.     
  43. $white = ImageColorAllocate($im, 255, 255, 255);     
  44.     
  45. $blue = ImageColorAllocate($im, 0, 0, 64);     
  46.     
  47. ImageFill($im, 0, 0, $white);     
  48.     
  49. srand((double)microtime()*1000000000);     
  50.     
  51. ImageLine($im, mt_rand(0,$width/3), mt_rand(0,$height/3), mt_rand($width/3,$width), mt_rand($height/3,$height), $blue);     
  52.     
  53. srand((double)microtime()*1000000);     
  54.     
  55. ImageLine($im, mt_rand($width/3,$width), mt_rand(0,$height/3), mt_rand(0,$width/3), mt_rand(0,$height/3), $blue);     
  56.     
  57. srand((double)microtime()*1000000);     
  58.     
  59. ImageString($im,16 , mt_rand(0,$width - strlen($randval) * 10), mt_rand(0,$height-12), $randval, $blue);     
  60.     
  61. ImageGIF($im);     
  62.     
  63. ImageDestroy($im);     
  64.     
  65. /*     
  66.     
  67. 需要注意的是:為了支持以上繪圖函數(shù),我們必須在PHP載入GD2圖形處理庫,可修改 php.ini 文件中的     
  68.     
  69. ;extension=php_gd2.dll     
  70.     
  71. 為     
  72.     
  73. extension=php_gd2.dll     
  74.     
  75. 即開啟GD2庫     
  76.     
  77. */     
  78.     
  79. ?>    

三、這是驗證頁面,提示PHP驗證碼是否通過驗證

 
 
 
  1.  @header("content-type:text/html; charset=UTF-8");     
  2.     
  3.     //開啟session     
  4.     
  5.     session_start();     
  6.     
  7.     //得到用戶輸入的驗證碼,并轉(zhuǎn)換成大寫     
  8.     
  9.     $imgId_req = $_REQUEST['imgId'];     
  10.     
  11.     $imgId_req = strtoupper($imgId_req);     
  12.     
  13.     //驗證該字符串是否注冊了session變量     
  14.     
  15.     if (session_is_registered($imgId_req)) {     
  16.     
  17.        echo " color=blue >通過驗證!";     
  18.     
  19.     } else {     
  20.     
  21.        echo " color=red >驗證錯誤!";     
  22.     
  23.     }     
  24.     
  25.     //關閉session,以清除所有注冊過的變量     
  26.     
  27.     session_destroy();     
  28.     
  29. ?>    

名稱欄目:PHP驗證碼在驗證頁面中的應用分析
網(wǎng)頁路徑:http://www.5511xx.com/article/cdshiij.html