Home > Backend Development > PHP Tutorial > Simple PHP verification image generation function_PHP tutorial

Simple PHP verification image generation function_PHP tutorial

WBOY
Release: 2016-07-21 15:46:35
Original
919 people have browsed it

Copy code The code is as follows:

function yzm($name,$width,$height){
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//Sow a seed to generate random numbers to facilitate the use of random number generation below
session_start();//Save random numbers into the session
$_SESSION[$name]="";
$im = imagecreate($width,$height); //Set the image background size
$black = ImageColorAllocate($im, 0,0,0); //Set three colors
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200 );
imagefill($im,0,0,$gray); //Use area filling method, set (0,0)
while(($authnum=rand()%100000)<10000 );
$_SESSION[$name]=$authnum;
imagestring($im, 5, 10, 3, $authnum, $black);
for($i=0;$i<200 ;$i++)//Add interference pixels
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand ()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
}?>

To use it, create a php file into yzm.php, call
Call the parameters into this function. .

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320105.htmlTechArticleCopy the code as follows: ?php function yzm($name,$width,$height){ Header("Content -type: image/PNG"); srand((double)microtime()*1000000);//Sow a seed to generate random numbers,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template