Session_start (); // Generate a verification code Image Header ("Content-type: image/png "); // All numbers $ Str = "1, 2, 3, 4, 5, 6, 7, 8, 9, a, B, c, d, f, g"; // you can add or delete the characters to be displayed. $ List = explode (",", $ str ); $ Cmax = count ($ list)-1; $ VerifyCode = ''; For ($ I = 0; $ I <5; $ I ++ ){ $ Randnum = mt_rand (0, $ cmax ); $ VerifyCode. = $ list [$ randnum]; // extract the characters and combine them into the verification code characters. } $ _ SESSION ['code'] = $ verifyCode; // put the characters in the SESSION $ Im = imagecreate (58,28); // generate an image $ Black = imagecolorallocate ($ im, 0); // set the color of the Bar and the following three items $ White = imagecolorallocate ($ im, 255,255,255 ); $ Gray = imagecolorallocate ($ im, 200,200,200 ); $ Red = imagecolorallocate ($ im, 255, 0, 0 ); Imagefill ($ im, $ white); // fill the color of the image // Print the verification code into the image Imagestring ($ im, 5, 10, 8, $ verifyCode, $ black); // write the verification code to the image. For ($ I = 0; $ I <50; $ I ++) // Add interference pixels { Imagesetpixel ($ im, rand () p, rand () 0, $ black); // Add point interferon Imagesetpixel ($ im, rand () p, rand () 0, $ red ); Imagesetpixel ($ im, rand () p, rand () 0, $ gray ); // Imagearc ($ im, rand () p, rand () p, 20, 20, 75,170, $ black); // Add an arc-like interferon // Imageline ($ im, rand () p, $ red); // Add line-like interferon } Imagepng ($ im ); Imagedestroy ($ im ); ?> |