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

首頁 > 語言 > PHP > 正文

php簡單生成驗證碼

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

利用php自身帶的函數來實現圖片驗證碼生成功能,php簡單生成驗證碼實例代碼如下:

  1. <?php 
  2. //must start or continue session and save CAPTCHA string in $_SESSION for  
  3. //it to be available to other requests  
  4. if(!isset($_SESSION)){  
  5. session_start();  
  6. header('Cache-control:private');  
  7. }  
  8. //create a 65*20 pixel image  
  9. $width=65;  
  10. $height=20;  
  11. $image=imagecreate(65,20);  
  12. //fill the image background color  
  13. $bg_color=imagecolorallocate($image,0x33,0x66,0xFF);  
  14. imagefilledrectangle($image,0,0,$width,$height,$bg_color);  
  15. //fetch random text  
  16. $text=random_text(5);  
  17. //determine x and y coordinates for centering text  
  18. $font=5;  
  19. $x=imagesx($image)/2-strlen($text)*imagefontwidth($font)/2;  
  20. $y=imagesy($image)/2-imagefontheight($font)/2;  
  21. //write text on image //開源代碼Vevb.com 
  22. $fg_color=imagecolorallocate($image,0xFF,0xFF,0xFF);  
  23. imagestring($image,$font,$x,$y,$text,$fg_color);  
  24. //save the CAPTCHA string for later comparison  
  25. $_SESSION['captcha']=$text;  
  26. //output the image  
  27. header('Content-type:image/png');  
  28. imagepng($image);  
  29. imagedestroy($image);  
  30. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵寿县| 永康市| 惠来县| 肃北| 铜陵市| 鄯善县| 咸宁市| 泽库县| 栾川县| 南丰县| 新宁县| 和硕县| 阿勒泰市| 五峰| 长海县| 伊宁县| 大邑县| 宁陵县| 廉江市| 普陀区| 康马县| 鄂伦春自治旗| 盐源县| 沿河| 龙海市| 阜康市| 铜陵市| 阳江市| 外汇| 太湖县| 如东县| 崇明县| 乌鲁木齐县| 来凤县| 池州市| 德令哈市| 来宾市| 平乡县| 莆田市| 北安市| 商水县|