The php code used to create the verification code for the GD Library:
4, // verification code length 'code _ size' => 20, // The verification code font size 'code _ width' => 100, // the width of the verification code box 'code _ height' => 30, // The height of the verification code box 'code _ num' => true, // enable the digit 'code _ upper '=> true, // enable the uppercase letter 'code _ lower' => true, // enable the lower-case letter 'code _ delete' => '1li0oo2zz '// exclude obfuscation characters ); // Convert the configuration item to the corresponding variable foreach ($ code_ini as $ key => $ value) {$ key = $ value ;} // Create a verification code canvas $ code_img = imagecreatetruecolor ($ code_width, $ code_height); $ black = imagecolorallocate ($ code_img, 0, 0, 0 ); // fill in random background color $ bg = imagecolorallocate ($ code_img, rand (200,255), rand (200,255), rand (200,255); imagefill ($ code_img, 0, 0, $ bg); // randomly draw 100 interference points for ($ I = 0; $ I <100; $ I ++) {$ color = imagecolorallocate ($ code_img, rand (0,200), rand (0,200), rand (0,200); imagesetpixel ($ code_img, rand (2, $ code_width-2), rand (2, $ code_height-2 ), $ color) ;}// randomly draw 10 interference lines for ($ q = 0; $ q <10; $ q ++) {$ color = imagecolorallocate ($ code_img, rand (0,200), rand (0,200), rand (0,200); imageline ($ code_img, rand (2, $ code_width-2), rand (2, $ code_height-2 ), rand (2, $ code_width-2), rand (2, $ code_height-2), $ color);} // Get the verification code $ code = get_code ($ code_count, $ code_num, $ code_upper, $ code_lower, $ code_remove); for ($ I = 0; $ I <$ code_count; $ I ++) {$ color = imagecolorallocate ($ code_img, rand (0,200 ), rand (0,200), rand (0,200); imagettftext ($ code_img, $ code_size, rand (-30, 30), 5 + 20 * $ I, 24, $ color, '.. /fonts/msyh. ttf', $ code [$ I]);} imagerectangle ($ code_img, 0, 0, $ code_width-1, $ code_height-1, $ black ); // output the verification code header ('content-type: image/GIF'); imagegif ($ code_img); // destroy the imagedestroy ($ code_img) resource ); // Obtain the verification code function get_code ($ code_count, $ code_num, $ code_upper, $ code_lower, $ code_remove) {$ num = array (); $ upper = array (); $ lower = array (); if ($ code_num) {$ num = range (0, 9);} if ($ code_upper) {$ upper = range ('A ', 'Z');} if ($ code_lower) {$ lower = range ('A', 'z ');} // merge the matching array $ arr = array_merge ($ num, $ lower, $ upper); // exclude obfuscation characters $ remove = str_split ($ code_remove ); $ arr1 = array_diff ($ arr, $ remove); $ mess = ''; for ($ I = 0; $ I <$ code_count; $ I ++) {$ mess. = $ arr1 [array_rand ($ arr1)];} return $ mess ;}