<? Header ("Content-type: image/png "); // Define the header and declare the image file, preferably png, without copyright concerns; // Generate a new four-digit integer Verification Code Session_start (); // enable session; Authnum_session = ''; 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 <= 4; 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_session. = str [num]; // Connects the characters obtained from numbers to a total of four digits; } Session_register ("authnum_session "); // It is good to use the session for verification. register the session and name it authnum_session, // If other pages contain the image // It can be called through _ SESSION ["authnum_session "] // Generate the verification code image, Srand (double) microtime () * 1000000 ); Im = imagecreate (50, 20); // image width and height; // Black, white, and gray colors are used; Black = ImageColorAllocate (im, 0, 0 ); White = ImageColorAllocate (im, 255,255,255 ); Gray = ImageColorAllocate (im, 200,200,200 ); // Print the four-digit integer verification code into the image Imagefill (im, 68, 30, gray ); // Comment out the line without interfering with the line; Li = ImageColorAllocate (im, 220,220,220 ); 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, 40), rand (), li ); } // The Position of the character in the image; Imagestring (im, 5, 8, 2, authnum_session, white ); For (I = 0; I <90; I ++) {// Add interference pixels Imagesetpixel (im, rand () % 70, rand () % 30, gray ); } ImagePNG (im ); ImageDestroy (im ); ?> |