ホームページ  >  記事  >  バックエンド開発  >  PHPアプリケーションソリューション

PHPアプリケーションソリューション

WBOY
WBOYオリジナル
2016-06-13 13:15:27774ブラウズ

PHP クラスの使用
私はクラスの概念に触れたばかりの初心者です。今、インターネット上で検証コードを生成するクラスを見つけました。クラス内で生成された検証コードを出力するにはどうすればよいですか。確認コードを出力する必要がありますか?クラスのコードは次のようになります。
class AuthCode
{
var $sBgcolor;
var $nWidth; nHeight ;
var $nLen;
var $nNoise;
var $aFontlist; > $this->sBgcolor = "#FFFFFF";
$this->nWidth = 70;
$this->nLeftMargin = 5; - >nRightMargin = 5;
$this->nBottomMargin = 4;
$this->bNoise = true;
$this->nNoisePoint = 50;
$this->bBorder = true;

$this->aFontlist = "arial.ttf" ;
}

関数 OutputImg()
{
$this->image = "";
$this->image = imagecreate($this->nWidth, $this - >nHeight);
$back = $this->getcolor($this->sBgcolor);
imagefilledrectangle($this->image, 0, 0, $this->nWidth, $this->nHeight , $back);
$size = ($this->nWidth - $this->nLeftMargin - $this->nRightMargin)/$this->nLen; nHeight - $this->nTopMargin - $this->nBottomMargin))
$size=$this->nHeight - $this->nTopMargin - $this->nBottomMargin

$left = ($ this ->nWidth-$this->nLen*($size+$size/10))/2 + $this->nLeftMargin;
$code = ""
for ($i=0; $i
nLen; $i++)
{
$randtext = rand(0, 9);
$code .= $randtext;
$textColor = imagecolorallocate($this->image, rand) ( 0, 100), rand(0, 100), rand(0, 100));
$font = $this->aFontlist
$randsize = rand($size-$size/10, $サイズ+ $size/10);
$location = $left+($i*$size+$size/10);
imagettftext($this->image, $randsize, rand(-18,18); location , rand($size, $size+$size/5) + $this->nTopMargin, $textColor, $font, $randtext);
}
if($this->bNoise == true) $ this ->setnoise();
$_SESSION['yzm'] = md5($code);
$bordercolor = $this->getcolor("#FFFFFF"); > bBorder==true) imagerectangle($this->image, 0, 0, $this->nWidth-1, $this->nHeight-1, $bordercolor); header("Content-type: image/ png ");
imagepng($this->image);
imagedestroy($this->image);
}
function setnoise()//ノイズポイントを設定
{
for ($i=0; $i
nNoiseLine; $i++){
$randColor = imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0) , 255 ));
imageline($this->image, rand(0, $this->nWidth), rand(0, $this->nHeight), rand(0, $this->nWidth), rand (0 , $this->nHeight), $randColor);
}

for ($i=0; $i
nNoisePoint; $i++){
$randColor = imagecolorallocate( $this ->image, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($this->image, rand(0, $this->nWidth), rand( 0, $this->nHeight), $randColor);

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