中国語の英数字、カスタム フォントの 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衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

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

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

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

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

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

ホットトピック









PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

このチュートリアルでは、PHPを使用してXMLドキュメントを効率的に処理する方法を示しています。 XML(拡張可能なマークアップ言語)は、人間の読みやすさとマシン解析の両方に合わせて設計された多用途のテキストベースのマークアップ言語です。一般的にデータストレージに使用されます

あなたが経験豊富な PHP 開発者であれば、すでにそこにいて、すでにそれを行っていると感じているかもしれません。あなたは、運用を達成するために、かなりの数のアプリケーションを開発し、数百万行のコードをデバッグし、大量のスクリプトを微調整してきました。

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

文字列は、文字、数字、シンボルを含む一連の文字です。このチュートリアルでは、さまざまな方法を使用してPHPの特定の文字列内の母音の数を計算する方法を学びます。英語の母音は、a、e、i、o、u、そしてそれらは大文字または小文字である可能性があります。 母音とは何ですか? 母音は、特定の発音を表すアルファベットのある文字です。大文字と小文字など、英語には5つの母音があります。 a、e、i、o、u 例1 入力:string = "tutorialspoint" 出力:6 説明する 文字列「TutorialSpoint」の母音は、u、o、i、a、o、iです。合計で6元があります

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

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