国产探花免费观看_亚洲丰满少妇自慰呻吟_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">

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 伊春市| 临高县| 凤冈县| 荥经县| 栾城县| 越西县| 泰安市| 旬邑县| 肇庆市| 祁门县| 化德县| 临城县| 慈溪市| 巍山| 沐川县| 偃师市| 丹东市| 宁陵县| 图片| 吉木萨尔县| 永仁县| 平远县| 高尔夫| 当雄县| 咸丰县| 濉溪县| 华阴市| 堆龙德庆县| 股票| 勃利县| 蓬安县| 金湖县| 偏关县| 花莲县| 舟曲县| 新野县| 杭锦旗| 双江| 电白县| 曲阜市| 荥经县|