<?
Header ("Content-Type: image/PNG ");
// Define the header and declare the image file, preferably PNG, without copyright concerns;
$ Authnum = "";
// Define the number to be displayed to generate a new four-digit integer Verification Code
$ STR = 'abcdefghijkmnpqrstuvwxyz1234567890 ';
// Define the numbers and letters used to display on the image;
$ L = strlen ($ Str); // obtain the string length;
// Cyclically and randomly extract four letters and numbers defined above;
For ($ I = 1; $ I <5; $ I ++)
{
$ Num = rand (0 L-1 );
// A number is randomly selected at a time. From the first word to the maximum length of the string,
// Minus 1 is because the truncation character starts from 0, so that any 34 characters may be listed in it;
$ Authnum. = $ STR [$ num];
// Connects the characters obtained from numbers to a total of four digits;
}
Setcookie ("authnum", $ authnum );
// Store four digits and letters in the cookie named authnum;
// Generate the verification code image,
Srand (double) microtime () * 1000000 );
$ Im = imagecreate (); // image width and height;
// Black, white, and gray colors are used;
$ Black = imagecolorallocate ($ im, 255,255,255 );
$ White = imagecolorallocate ($ im, 218,133, 82 );
$ Gray = imagecolorallocate ($ im, 200,200,200 );
// Comment out the line without interfering with the line;
// $ Li = imagecolorallocate ($ im, 120,220,200 );
$ Li = imagecolorallocate ($ im, 0, 0 );
For ($ I = 0; $ I <3; $ I ++)
{// Add three interference lines; or do not; depending on the situation, because it may affect user input;
Imageline ($ im, Rand (), Rand (), Rand (20, 60), Rand (), $ Li );
}
// Print the four-digit integer verification code into the image
Imagefill ($ im, 272,120, $ gray );
// The Position of the character in the image;
Imagestring ($ im, 5, 14, 3, $ authnum, $ white );
For ($ I = 0; $ I <90; $ I ++)
{// Add interference pixels
Imagesetpixel ($ im, Rand () % 70, Rand () % 30, $ gray );
}
Imagepng ($ IM );
Imagedestroy ($ IM );
?>