色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP高自定義性安全驗(yàn)證碼代碼

復(fù)制代碼 代碼如下:
<?php
public function captcha(){
$font_dir = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"; // 字體庫(kù)
$img_w = 58; // 設(shè)置圖片寬
$img_h = 20; // 設(shè)置圖片高
$font_size = 11; // 字體大小
$angle_l = -10; // 左偏角
$angle_r = 10; // 右偏角
$code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36";
$word_len = 4; // 驗(yàn)證碼位數(shù)
$padding = 5; // 每?jī)蓚€(gè)文字之間間隔
$margin = 2; // 左側(cè)邊距
$base_line = 15; // 文字基線位置
$base_line_offset = 2; // 基準(zhǔn)線偏移量
$pixel_num = 3; // 雜點(diǎn)數(shù)目基數(shù)
$pixel_color= 8; // 雜點(diǎn)只有 $pixel_color 種顏色 總的雜點(diǎn)數(shù)為$pixel_num*$pixel_color
$noise_font_size = 1; // 雜點(diǎn)字體大小
$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)));

//繪制雜點(diǎn)
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;
}

php技術(shù)PHP高自定義性安全驗(yàn)證碼代碼,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 保靖县| 芒康县| 兴城市| 兰西县| 濮阳市| 临清市| 桦甸市| 曲靖市| 兴化市| 江城| 巩义市| 顺义区| 黄石市| 阳山县| 逊克县| 全州县| 南涧| 太谷县| 拜泉县| 龙游县| 新安县| 呼伦贝尔市| 和硕县| 宁蒗| 大渡口区| 祁阳县| 庆城县| 扬中市| 灵川县| 肇源县| 太白县| 新民市| 北海市| 景谷| 辉县市| 即墨市| 荣昌县| 洞口县| 蓬安县| 汕尾市| 比如县|