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

首頁 > 開發(fā) > PHP > 正文

PHP高自定義性安全驗證碼代碼

2024-05-04 23:16:29
字體:
供稿:網(wǎng)友

復制代碼 代碼如下:


<?php
public function captcha(){
$font_dir = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"; // 字體庫
$img_w = 58; // 設(shè)置圖片寬
$img_h = 20; // 設(shè)置圖片高
$font_size = 11; // 字體大小
$angle_l = -10; // 左偏角
$angle_r = 10; // 右偏角
$code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36";
$word_len = 4; // 驗證碼位數(shù)
$padding = 5; // 每兩個文字之間間隔
$margin = 2; // 左側(cè)邊距
$base_line = 15; // 文字基線位置
$base_line_offset = 2; // 基準線偏移量
$pixel_num = 3; // 雜點數(shù)目基數(shù)
$pixel_color= 8; // 雜點只有 $pixel_color 種顏色 總的雜點數(shù)為$pixel_num*$pixel_color
$noise_font_size = 1; // 雜點字體大小
$session_key= "my.xoyo_captcha"; //自定義session鍵名

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
header("Cache-control: private");
header('Content-Type: image/png');

session_start();
$word = "";
$code_str_len = strlen($code_str) - 1;
for ($i = 0; $i < $word_len; $i++) {
$word.= $code_str[rand(0, $code_str_len)];
}
$_SESSION [$session_key] = strtolower($word);
$image = imagecreatetruecolor($img_w, $img_h);
imagefilledrectangle($image, 0, 0, $img_w - 1, $img_h - 1, imagecolorallocate($image, mt_rand(235, 255), mt_rand(235, 255), mt_rand(235, 255)));

//繪制雜點
for($i = 0; $i < $pixel_color; $i++){
$noise_color = imagecolorallocate( $image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225) );
for($j = 0; $j < $pixel_num; $j++) {
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 );
}
}

//繪制文字
for ($i = 0; $i < $word_len; ++$i) {
$color = imagecolorallocate($image, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
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'));
$margin += (imagefontwidth($font_size) + $padding);
}

imagepng($image);
imagedestroy($image);
exit;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳原县| 大悟县| 土默特右旗| 剑川县| 华池县| 泾阳县| 宁武县| 井研县| 疏勒县| 马公市| 彰化市| 河津市| 磴口县| 夏津县| 福建省| 高邮市| 饶河县| 达日县| 凌源市| 长沙县| 抚州市| 嘉禾县| 睢宁县| 巴东县| 布尔津县| 伊金霍洛旗| 定陶县| 南华县| 尉犁县| 大姚县| 谷城县| 商水县| 彭山县| 柳林县| 环江| 崇文区| 方正县| 滨州市| 平湖市| 什邡市| 台北县|