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

首頁(yè) > 語(yǔ)言 > PHP > 正文

php高安全驗(yàn)證碼生成程序

2024-09-04 11:44:07
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本生成程序需要調(diào)用一些字體庫(kù),你可以調(diào)用你系統(tǒng)自帶的一些字體,當(dāng)然也可以像dedecms一樣自己把字體放到一個(gè)目錄,這樣在服務(wù)器上也可以使用.

php高安全驗(yàn)證碼生成程序?qū)嵗a如下:

  1. <?php  
  2. public function captcha(){  
  3. $font_dir = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"// 字體庫(kù)  
  4. $img_w = 58; // 設(shè)置圖片寬  
  5. $img_h = 20; // 設(shè)置圖片高  
  6. $font_size = 11; // 字體大小  
  7. $angle_l = -10; // 左偏角  
  8. $angle_r = 10; // 右偏角  
  9. $code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36";  
  10. $word_len = 4; // 驗(yàn)證碼位數(shù)  
  11. $padding = 5; // 每?jī)蓚€(gè)文字之間間隔  
  12. $margin = 2; // 左側(cè)邊距  
  13. $base_line = 15; // 文字基線位置  
  14. $base_line_offset = 2; // 基準(zhǔn)線偏移量  
  15. $pixel_num = 3; // 雜點(diǎn)數(shù)目基數(shù)  
  16. $pixel_color= 8; // 雜點(diǎn)只有 $pixel_color 種顏色 總的雜點(diǎn)數(shù)為$pixel_num*$pixel_color  
  17. $noise_font_size = 1; // 雜點(diǎn)字體大小  
  18. $session_key"my.xoyo_captcha"//自定義session鍵名 
  19.  
  20. header("Cache-Control: no-cache, must-revalidate");  
  21. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
  22. header("Pragma: no-cache");  
  23. header("Cache-control: private");  
  24. header('Content-Type: image/png'); 
  25.  
  26. session_start();  
  27. $word = "";  
  28. $code_str_len = strlen($code_str) - 1;  
  29. for ($i = 0; $i < $word_len$i++) {  
  30. $word.= $code_str[rand(0, $code_str_len)];  
  31. }  
  32. $_SESSION [$session_key] = strtolower($word);  
  33. $image = imagecreatetruecolor($img_w$img_h);  
  34. imagefilledrectangle($image, 0, 0, $img_w - 1, $img_h - 1, imagecolorallocate($image, mt_rand(235, 255), mt_rand(235, 255), mt_rand(235, 255))); 
  35.  
  36. //繪制雜點(diǎn)  
  37. for($i = 0; $i < $pixel_color$i++){  
  38. $noise_color = imagecolorallocate( $image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225) );  
  39. for($j = 0; $j < $pixel_num$j++) {  
  40. imagestring( $image$noise_font_size, mt_rand(-10, $img_w), mt_rand(-10, $img_h), $code_str[mt_rand(0, $code_str_len)], $noise_color );  
  41. }  
  42.  
  43. //繪制文字  
  44. for ($i = 0; $i < $word_len; ++$i) {  
  45. $color = imagecolorallocate($image, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));  
  46. imagettftext($image$font_size, mt_rand($angle_l$angle_r), $margin, mt_rand($base_line-$base_line_offset$base_line+$base_line_offset), $color$font, mb_substr($word$i, 1, 'utf-8'));  
  47. $margin += (imagefontwidth($font_size) + $padding);  
  48. }//開(kāi)源代碼Vevb.com 
  49.  
  50. imagepng($image);  
  51. imagedestroy($image);  
  52. exit;  
  53. ?> 

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 图片| 桐乡市| 集贤县| 池州市| 英德市| 宁城县| 开化县| 华宁县| 台湾省| 辽阳市| 社旗县| 静安区| 松滋市| 彭州市| 湖北省| 阳春市| 诸城市| 崇义县| 宿州市| 莎车县| 鲜城| 丰城市| 马关县| 确山县| 综艺| 九江市| 泸水县| 济南市| 全椒县| 宜良县| 贵溪市| 舒城县| 普兰店市| 漳平市| 梨树县| 化德县| 温泉县| 塔河县| 黑水县| 赞皇县| 增城市|