中国語の英数字、カスタム フォントの PHP 検証コード コードをサポート
コードをコピー コードは次のとおりです:
/*
* PHP GD Lib ベースの Captcha クラス
* @author Design
* @version 1.0
* @demo
* include('captchaClass.php');
* $captchaDemo=new Captcha();
* $captchaDemo->createImage();
クラス キャプチャ{
// @検証コード画像の高さを定義します
private $height; //@検証コード画像の幅を定義します
private $width; //@検証コードの文字数を定義します
$textNum;
//@検証コードの文字内容を定義します
private $textContent; //@文字の色を定義します
//@ランダムなテキストの色を定義します
private $randFontColor;
//@フォント サイズを定義
private $fontSize; ;
//@ランダムな背景色を定義します
private $randBgColor;
//@文字言語を定義します
//@干渉点の数を定義します
private $noisePoint;
//@干渉ラインの数を定義します
private $noiseLine;
//@歪ませるかどうかを定義します
private $distortion;画像ソース
private $distortionImage;
//@境界線があるかどうかを定義します
private $showBorder;
//@検証コード画像ソースを定義します
private $image;
//@Constructor コンストラクター
public function Captcha(){
$this->gt;textNum=4;
$this->fontFamily; ='c:windowsfontsSIMYOU.ttf'; //中国語フォントを設定します。Linux ディレクトリに変更できます
$this->textLang='en';
$this->noiseLine=3;
$this->distortion=false;
}
//@画像の幅を設定します
public function setWidth($w){
$this->width=$w>
//@画像の高さを設定します
public function setHeight($h){
$this->height=$h;
}
//@文字数を設定します
public function setTextNumber($textN) ){
$this->textNum=$textN ;
}
//@文字色の設定
public function setFontColor($fc){
$this-> fontColor=sscanf($fc,'#%2x%2x% 2x');
}
//@フォントサイズを設定
public function setFontSize($n){
$this->fontSize=$n;
}
//@Set font
public function setFontFamily($ffUrl){
$this->fontFamily=$ffUrl; 🎜>}
//@文字言語を設定します
public function setTextLang($lang){
$this->textLang=$lang;
}
/ /@画像の背景を設定します
public function setBgColor($bc){
$this->bgColor=sscanf($bc,'#%2x%2x%2x');
}
//@干渉点の数を設定します
public function setNoisePoint($ n){
$this->noisePoint=$n;
// @干渉ライン数を設定
public function setNoiseLine($n){
$this- >noiseLine=$n>}
//@歪ませるかどうかを設定 public function setDistortion($b){
$this->distortion=$b;
}
//@ボーダーを表示するかどうかを設定します
public function setShowBorder($border) ){
$this->showBorder=$border;
}
// @初期化検証コード image
public function initImage(){
if($this ->width)){$this->width=floor($this->fontSize*1.3)*$this->textNum 10;}
if(empty($this->height)) {$this->height=$this->fontSize*2;}
$this->image =imagecreatetruecolor($this->width,$this->height);
if( empty($this->bgColor)){
$this->randBgColor=imagecolorallocate($this->image,mt_rand(100,255),mt_rand(100,255),mt_rand(100,255)); else{
$this->randBgColor=imagecolorallocate($this->image,$this->bgColor [0],$this->bgColor[1],$this->bgColor[2] );
}
imagefill($this->image,0,0,$this->randBgColor);
}
//@ランダムな文字を生成します
function randText($type){
$string='';
switch($type){
case 'en':
$str='ABCDEFGHJKLMNPQRSTUVWXY3456789'; =0;$i<$this->textNum;$i ){
$string=$string.' ,'.$str[mt_rand(0,29)];
}
break;
case 'cn':
for($i=0;$i<$this->textNum ;$i ) {
$string=$string.','.chr(rand(0xB0 ,0xCC)).chr(rand(0xA1,0xBB));
}
$string=iconv( 'GB2312','UTF-8',$string); //エンコーディングを utf8 に変換します。 Break;
}
return substr($string,1);
//@検証コードにテキストを出力
public function createText(){
$textArray =explode(',',$this->randText($this->textLang));
$ this->textContent=join('',$textArray);
if(empty($ this->fontColor)){
$this->randFontColor=imagecolorallocate($this->image, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
}else{
$this->randFontColor=imagecolorallocate($this->image,$this->fontColor[0] ,$this->fontColor[1],$this->fontColor[2]); 🎜>}
for($i=0;$itextNum;$i ){
$angle=mt_rand(-1,1)*mt_rand(1,20);
imagettftext($this->image,$this->fontSize,$angle,5 $i*floor($this->fontSize*1.3),floor($this->height*0.75), $this->randFontColor,$this->fontFamily,$textArray[$i]);
}
}
//@ 生成干扰点
public function createNoisePoint(){
for($i=0;$i<$this->noisePoint;$ i ){
$pointColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($this->image,mt_rand(0,$this->幅),mt_rand(0,$this->高さ),$pointColor);
}
}
//@产生干扰線
public function createNoiseLine(){
for($i=0;$i<$this->ノイズライン;$i ) {
$lineColor=imagecolorallocate($this->image,mt_rand(0,255),mt_rand(0,255),20);
imageline($this->image,0,mt_rand(0,$this->幅),$this->幅,mt_rand(0,$this->高さ),$lineColor);
}
}
//@扭曲文字
public functiondistortionText(){
$this->distortionImage=imagecreatetruecolor($this->width,$this- >身長);
imagefill($this->distortionImage,0,0,$this->randBgColor);
for($x=0;$xwidth;$x ){
for($y=0;$yheight;$y ){
$rgbColor=imagecolorat($this->image,$x,$y);
imagesetpixel($this->distortionImage,(int)($x sin($y/$this->height*2*M_PI-M_PI*0.5)*3),$y,$rgbColor);
}
}
$this->image=$this->distortionImage;
}
//@生成验证码图片
public function createImage(){
$this->initImage(); //基本的な画像を作成
$this->createText(); //输出验证码文字
if($this->distortion){$this->distortionText();} //扭曲文字
$this->createNoisePoint(); //産干扰点
$this->createNoiseLine(); //産干扰線
if($this->showBorder){imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$ this->randFontColor);} //追加边框
imagepng($this->image);
imagedestroy($this->image);
if($this->distortion){imagedestroy($this->$distortionImage);}
return $this->textContent;
}
}
?>使用方法:
//session_start();
header("Content-type:image/png");
include('captcha5_class.php');
$captcha5=新しいキャプチャ();
//@设置验证码宽度
//$captcha5->setWidth(200);
//@设置验证码高さ
//$captcha5->setHeight(50);
//@设置文字数
$captcha5->setTextNumber(5);
//@设置字符颜色
//$captcha5->setFontColor('#ff9900');
//@设置文字号大小
//$captcha5->setFontSize(25);
//@设置文字体
$captcha5->setFontFamily('c:windowsfontsSTXINGKA.TTF');
//@设置语言
$captcha5->setTextLang('cn');
//@设置背景颜色
//$captcha5->setBgColor('#000000');
//@设置干扰点数
//$captcha5->setNoisePoint(600);
//@设置干扰線数
//$captcha5->setNoiseLine(10);
//@设置是否扭曲
//$captcha5->setDistortion(true);
//@設置かどうか表示边框
$captcha5->setShowBorder(true);
//出验证码
$code=$captcha5->createImage();
//$_SESSION['captchaCode']['content']=$code;
//$_SESSION['captchaCode']['time']=microtime();
?>

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

静的結合(静的::) PHPで後期静的結合(LSB)を実装し、クラスを定義するのではなく、静的コンテキストで呼び出しクラスを参照できるようにします。 1)解析プロセスは実行時に実行されます。2)継承関係のコールクラスを検索します。3)パフォーマンスオーバーヘッドをもたらす可能性があります。

PHPとPythonにはそれぞれ独自の利点があり、プロジェクトの要件に従って選択します。 1.PHPは、特にWebサイトの迅速な開発とメンテナンスに適しています。 2。Pythonは、データサイエンス、機械学習、人工知能に適しており、簡潔な構文を備えており、初心者に適しています。

PHPの魔法の方法は何ですか? PHPの魔法の方法には次のものが含まれます。1。\ _ \ _コンストラクト、オブジェクトの初期化に使用されます。 2。\ _ \ _リソースのクリーンアップに使用される破壊。 3。\ _ \ _呼び出し、存在しないメソッド呼び出しを処理します。 4。\ _ \ _ get、dynamic属性アクセスを実装します。 5。\ _ \ _セット、動的属性設定を実装します。これらの方法は、特定の状況で自動的に呼び出され、コードの柔軟性と効率を向上させます。

PHPは、サーバー側で広く使用されているスクリプト言語で、特にWeb開発に適しています。 1.PHPは、HTMLを埋め込み、HTTP要求と応答を処理し、さまざまなデータベースをサポートできます。 2.PHPは、ダイナミックWebコンテンツ、プロセスフォームデータ、アクセスデータベースなどを生成するために使用され、強力なコミュニティサポートとオープンソースリソースを備えています。 3。PHPは解釈された言語であり、実行プロセスには語彙分析、文法分析、編集、実行が含まれます。 4.PHPは、ユーザー登録システムなどの高度なアプリケーションについてMySQLと組み合わせることができます。 5。PHPをデバッグするときは、error_reporting()やvar_dump()などの関数を使用できます。 6. PHPコードを最適化して、キャッシュメカニズムを使用し、データベースクエリを最適化し、組み込み関数を使用します。 7

PHPは、電子商取引、コンテンツ管理システム、API開発で広く使用されています。 1)eコマース:ショッピングカート機能と支払い処理に使用。 2)コンテンツ管理システム:動的コンテンツの生成とユーザー管理に使用されます。 3)API開発:RESTFUL API開発とAPIセキュリティに使用されます。パフォーマンスの最適化とベストプラクティスを通じて、PHPアプリケーションの効率と保守性が向上します。

PHP8では、一致式は、式の値に基づいて異なる結果を返す新しい制御構造です。 1)Switchステートメントに似ていますが、実行ステートメントブロックの代わりに値を返します。 2)一致式の式は厳密に比較され、セキュリティが向上します。 3)スイッチステートメントの脱落の可能性を回避し、コードのシンプルさと読みやすさを向上させます。

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHPは、シンプルな構文と高い実行効率を備えたWeb開発に適しています。 2。Pythonは、簡潔な構文とリッチライブラリを備えたデータサイエンスと機械学習に適しています。
