The code for generating a verification code in php is as follows & lt ;? Php & nbsp; Header (Content-type: & nbsp; imagePNG); & nbsp; srand (double) microtime () * 1000000); play the next seed to generate random numbers to facilitate the following random number generation using sessi about php to generate verification code
The code is as follows:
Header ("Content-type: image/PNG ");
Srand (double) microtime () * 1000000); // play the next seed that generates random numbers to facilitate the use of the following random number generation
Session_start (); // Save the random number to the session.
$ _ SESSION ['authnum'] = "";
$ Im = imagecreate (70, 20) or die ("Cant's initialize new GD image stream! "); // Specifies the image background size.
$ Black = ImageColorAllocate ($ im, 0, 0); // you can specify three colors.
$ White = ImageColorAllocate ($ im, 255,255,255 );
$ Gray = ImageColorAllocate ($ im, 200,200,200 );
Imagefill ($ im, $ gray); // use the area filling method, set)
// Generate a verification code mixed with numbers and letters
$ Ychar = ", A, B, C, D, E, F, G, H, I, J, K, L, M, n, O, P, Q, R, S, T, U, V, W, X, Y, Z ";
$ List = explode (",", $ ychar );
For ($ I = 0; $ I <4; $ I ++ ){
$ Randnum = rand (0, 35 );
$ Authnum. = $ list [$ randnum];
}
// While ($ authnum = rand () % 100000) <10000); // Generate a random number of five students
// Print the five-digit integer verification code into the image
$ _ SESSION ['authnum'] = $ authnum;
Imagestring ($ im, 5, 10, 3, $ authnum, $ black );
// Use the col color to draw the string s to the x and y coordinates of the image (0 and 0 in the upper left corner of the image ).
// If the 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 () % 70, rand () % 30, $ randcolor );
}
ImagePNG ($ im );
ImageDestroy ($ im );
?>
The gd Library is also available, but images are not generated .. Please advise
------ Solution --------------------
Reference:
Enabled ..
The code is okay. first, set $ _ SESSION ['code'] = $ verifyCode; if you don't need to enable the session, it's probably your environment problem. I can test it here.