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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石城县| 石首市| 房产| 紫金县| 万全县| 厦门市| 万宁市| 宁武县| 江源县| 扬中市| 德兴市| 东台市| 芜湖县| 襄城县| 易门县| 从化市| 晋城| 滨海县| 海原县| 仁化县| 亳州市| 乌拉特后旗| 古蔺县| 建瓯市| 城口县| 旅游| 西城区| 芦溪县| 保靖县| 海兴县| 罗城| 陵水| 斗六市| 麦盖提县| 文水县| 普安县| 新蔡县| 丰镇市| 崇州市| 石楼县| 舒城县|