ホームページ  >  記事  >  バックエンド開発  >  PHP高セキュリティ検証コード生成プログラム_PHPチュートリアル

PHP高セキュリティ検証コード生成プログラム_PHPチュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:10:07836ブラウズ

この生成プログラムは、システムに付属のいくつかのフォントを呼び出す必要があります。もちろん、フォントを dedecms などのディレクトリに配置して、サーバー上で使用することもできます。

技術記事
コードは次のとおりです コードをコピー

パブリック関数 captcha(){
$font_dir = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"; // フォント ライブラリ
$img_w = 58 // 画像の幅を設定します
; $img_h = 20 //画像の高さを設定します
; $font_size = 11 // フォントサイズ
; $angle_l = -10 // 左偏角
; $angle_r = 10 // 右偏角
; $code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36"; $word_len = 4 // 認証コードの数字
; $padding = 5 // 各 2 つの単語の間にスペース
; $margin = 2 // 左マージン
; $base_line = 15 // テキストのベースラインの位置
; $base_line_offset = 2 // ベースライン オフセット
; $pixel_num = 3 // ノイズポイントの基本数
; $pixel_color= 8; // ノイズの色は $pixel_color だけです。ノイズの総数は $pixel_num*$pixel_color です。 $noise_font_size = 1 // ノイズのフォント サイズ
; $session_key= "my.xoyo_captcha" //セッションキー名をカスタマイズします

header("キャッシュ制御: キャッシュなし、再検証が必要"); header("有効期限: 1997 年 7 月 26 日月曜日 05:00:00 GMT"); header("プラグマ: キャッシュなし"); header("キャッシュ制御: プライベート"); header('Content-Type: image/png');

セッション開始(); $word = ""
$code_str_len = strlen($code_str) - 1; for ($i = 0; $i $word.= $code_str[rand(0, $code_str_len)]; }
$_SESSION [$session_key] = strto lower($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 $noise_color = imagecolorallocate( $image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225) ); for($j = 0; $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 $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); 出る
}








http://www.bkjia.com/PHPjc/629688.html

www.bkjia.com


tru​​e

http://www.bkjia.com/PHPjc/629688.html

この生成プログラムは、いくつかのフォント ライブラリを呼び出す必要があります。もちろん、フォントを dedecms などのディレクトリに配置してサーバー上に置くこともできます。
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。