ホームページ  >  記事  >  バックエンド開発  >  phpの簡単な確認コード

phpの簡単な確認コード

巴扎黑
巴扎黑オリジナル
2016-11-24 10:36:05878ブラウズ



classveriyimg {public $ fontsize = 15; public $im = null; //指定された幅と高さの画像を生成します

public $font = 'C:/Windows/Fonts/Arial.TTF';

public $strNum = "";

public function Build( ) {

$strings = Array ('1', '2','3', '4', '5', '6', '7' , 'a', 'b', 'c', ' d'、'e'、'f'、'h'、'i'、'j'、'k'、'm'、'n'、'p'、'r'、's'、' t', 'u', 'v', 'w', 'x', 'y' );

// $strNum = "";

$count = count ( $strings );

for($ i = 1; $i <= $this->length; $i ++) { //ランダムな文字をループして文字列を生成します

$strNum .= $strings [rand ( 0, $count - 1 ) ];

}

session_start ();

$_SESSION ["verifycode"] = $strNum;

$this->im = imagecreate ( $this-> ;width, $this->height );

$backgroundcolor = imagecolorallocate ( $this->im, 255, 255, 255 ); //背景色を生成します

$frameColor = imageColorAllocate ( $this->im , 0, 255, 0 );

($i = 0; $i length; $i ++) {

$charY = ($this->height + 9) / 2 + rand ( - 1, 1 ); /キャラクターのY座標を定義します

$charX = $i * 15 + 8; //キャラクターのX座標を定義します

// $text_color = imagecolorallocate($this->im, 255, 0, 0 ); ), mt_rand ( 50, 200 ) );

$angle = rand ( - 20, 20 ); // 文字の角度を生成

// 文字を書き込む

imagettftext ( $this->im, $this- >fontSize, $angle, $charX, $charY, $text_color, $this->font, $strNum [$i] );

}

for($i = 0; $i

$linecolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );

$linex = mt_rand ( 1, $this->width - 1 );

$liney = mt_rand ( 1, $this->height - 1 );

imageline ( $this->im, $linex , $liney, $linex + mt_rand ( 0, 4 ) - 2, $liney + mt_rand (0, 4) - 2, $linecolor );

}

for($i = 0; $i

$pointcolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );

imagesetpixel ( $this->im , mt_rand ( 1, $this->width - 1 ), mt_rand ( 1, $this->height - 1 ), $pointcolor );

}

imagerectangle ( $this->im, 0, 0 , $this->width - 1, $this->height - 1, $frameColor ) // 境界線を描画します

ob_clean ();

header ( 'Content-type:image/png' );

imagepng ( $this->im );

imagedestroy ( $this->im );

}

}

$img = new VerifyImg ();

$img->ビルド ();

?>

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。