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

首頁 > 語言 > PHP > 正文

php生成圖片驗證碼

2024-09-04 11:44:28
字體:
來源:轉載
供稿:網友

首先,有一個在php.ini看看gd庫是不是開啟的,下一步,我們會考慮每一個細節的圖像生成步驟.

php生成圖片驗證碼實例代碼如下:

  1. <?php  
  2. //Send a generated image to the browser  
  3. create_image();  
  4. exit(); 
  5.  
  6. function create_image()  
  7. {  
  8.     //Let's generate a totally random string using md5  
  9.     $md5 = md5(rand(0,999));  
  10.     //We don't need a 32 character long string so we trim it down to 5  
  11.     $pass = substr($md5, 10, 5); 
  12.  
  13.     //Set the image width and height  
  14.     $width = 100;  
  15.     $height = 20;  
  16.  
  17.     //Create the image resource  
  18.     $image = ImageCreate($width$height);  
  19.  
  20.     //We are making three colors, white, black and gray  
  21.     $white = ImageColorAllocate($image, 255, 255, 255);  
  22.     $black = ImageColorAllocate($image, 0, 0, 0);  
  23.     $grey = ImageColorAllocate($image, 204, 204, 204); 
  24.  
  25.     //Make the background black  
  26.     ImageFill($image, 0, 0, $black); 
  27.  
  28.     //Add randomly generated string in white to the image 
  29.     ImageString($image, 3, 30, 3, $pass$white); 
  30.  
  31.     //Throw in some lines to make it a little bit harder for any bots to 
  32.  
  33. break  
  34.     ImageRectangle($image,0,0,$width-1,$height-1,$grey);  
  35.     imageline($image, 0, $height/2, $width$height/2, $grey);  
  36.     imageline($image$width/2, 0, $width/2, $height$grey);  
  37.  
  38.     //Tell the browser what kind of file is come in  
  39.     header("Content-Type: image/jpeg"); 
  40. //開源代碼Vevb.com 
  41.     //Output the newly created image in jpeg format  
  42.     ImageJpeg($image);  
  43.      
  44.     //Free up resources 
  45.     ImageDestroy($image);  
  46. }  
  47. ?> 

驗證碼調用方法,代碼如下:

<img height="120" alt="Dynamically generated image" src="generate_image.php" width="200">

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 芮城县| 华池县| 公安县| 贵港市| 邵阳县| 高邑县| 永安市| 沛县| 灵山县| 双流县| 澄城县| 行唐县| 咸阳市| 大英县| 阳山县| 陆丰市| 蓝山县| 象山县| 海兴县| 宜宾县| 乌苏市| 兴宁市| 鹿泉市| 防城港市| 兰溪市| 东宁县| 江门市| 连城县| 应城市| 西充县| 云梦县| 林口县| 方山县| 乡宁县| 涿州市| 琼海市| 双牌县| 琼海市| 白银市| 方城县| 宁明县|