Home >Backend Development >PHP Tutorial >PHP version of verification code program_PHP tutorial

PHP version of verification code program_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:58:321048browse

//Generate verification code image
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 session
$_SESSION['authnum']="";
$im = imagecreate(62,20); //Specify 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); //Adopt area filling method, set (0,0)

while(($authnum=rand() 0000)<10000);
//Draw the four-digit integer verification code into the picture
$_SESSION['authnum']=$authnum;
imagestring($im, 5, 10, 3, $authnum, $black);
// Use col color to draw the string s to the x, y coordinates of the image represented by image (the upper left corner of the image is 0, 0).
//If font is 1, 2, 3, 4 or 5, use the built-in font

for($i=0;$i<200;$i ) //Add interference pixels
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()p , rand()0 , $randcolor);
}


ImagePNG($im);
ImageDestroy($im);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631989.htmlTechArticle?php //Generate verification code image 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...
Statement:
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