php 간편인증코드

巴扎黑
풀어 주다: 2016-11-24 10:36:05
원래의
883명이 탐색했습니다.



class verifyImg {

public $fontSize = 15; //글꼴 크기 정의

public $length = 4; //문자열 길이 정의                                                                  >          이미지 너비 정의

public $height = 30 ; //이미지 높이 정의

public $im = null; //지정된 너비와 높이로 이미지 생성

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

공개 $strNum = "";

공개 함수 Build() {

$strings = 배열('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 );

$backcolor = imagecolorallocate ( $this->im, 255, 255, 255 ) // 배경색 생성

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

for($i = 0; $i < $this->length; $i ++) {

$charY = ($this->height + 9) / 2 + rand ( - 1, 1 ); //문자 Y 좌표 정의

$charX = $i * 15 + 8; 문자 정의 문자 색상 생성

$text_color = imagecolorallocate ( $this->im, mt_rand ( 50, 255 ), mt_rand ( 50, 128 ), 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 < = 5; $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 <= 32; $i ++) { //홈 효과를 생성하기 위해 배경 점을 그리는 루프

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

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

}

imageRectangle ( $this- >im, 0, 0, $ this->width - 1, $this->height - 1, $frameColor ) //테두리 그리기

ob_clean ();

헤더( 'Content-type:image/ png' );

imagepng( $this->im );

imagedestroy( $this->im );

}

}

$img = new verifyImg();

$img->Build();

?>

관련 라벨:
php
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!