<? Php /** * Verify the image * Online files are modified by a Liang * 834114969@qq.com * Http://liuzhiliang.com/ */ Require_once (dirname (_ FILE _). "/common. inc. php "); // Session save path $ SessSavePath = DEDEDATA. "/sessions /"; If (is_writeable ($ sessSavePath) & is_readable ($ sessSavePath) {session_save_path ($ sessSavePath );} If (! Empty ($ pai_domain_cookie) session_set_cookie_params (0, '/', $ pai_domain_cookie ); Session_start (); // Obtain random characters $ Rndstring = ''; // $ Ch_h = chr (substr ($ num, 160) + ); // $ Ch_l = chr (substr ($ num, 160) + ); Function c2ch ($ num ){ $ Ch_h = chr (substr ($ num, 160) + ); $ Ch_l = chr (substr ($ num, 160) + ); Return $ ch_h. $ ch_l; } Function num_rand (){ Mt_srand (double) microtime () * 1000000 ); $ D = mt_rand (16, 36 ); $ N = mt_rand (1, 19 ); Return c2ch ($ d * 100 + $ n ); } For ($ I = 0; $ I <4; $ I ++) $ rndstring. = gb2utf8 (num_rand ()); // If GD is supported, draw If (function_exists ("imagecreate ")) { // In some cases in Firefox, there will be multiple requests, and refreshing the page within 5 seconds will not change the session $ Ntime = time (); If (empty ($ _ SESSION ['securimage _ code_value_last ']) | empty ($ _ SESSION ['securimage _ code_value']) | ($ ntime-$ _ SESSION ['securimage _ code_value_last ']> 1 )) { $ _ SESSION ['securimage _ code_value '] = strtolower ($ rndstring ); $ _ SESSION ['securimage _ code_value_last '] = $ ntime; } $ Rndstring = $ _ SESSION ['securimage _ code_value ']; // Create an image and set the background color $ X_size = 80; $ Y_size = 25; $ Font = 'simhei. Ttf '; $ Im = imagecreate ($ x_size, $ y_size ); $ Background_color = imagecolorallocate ($ instant, 255,255,255 ); // Random color $ FontColor [] = imagecolorallocate ($ im, 0x15, 0x15, 0x15 ); $ FontColor [] = imagecolorallocate ($ im, 0x95, 0x1e, 0x04 ); $ FontColor [] = imagecolorallocate ($ im, 0x93, 0x14, 0xa9 ); $ FontColor [] = imagecolorallocate ($ im, 0x12, 0x81, 0x0a ); $ FontColor [] = imagecolorallocate ($ im, 0x06, 0x3a, 0xd5 ); $ C_fontColor = $ fontColor [mt_rand (0, 4)]; Imagettftext ($ im, 15, mt_rand (-), 6, mt_rand (), $ c_fontColor, $ font, substr ($ rndstring )); Imagettftext ($ im, 15, mt_rand (-8), 37,20, $ c_fontColor, $ font, substr ($ rndstring, 6, 3 )); Imagettftext ($ im, mt_rand (15, 17), mt_rand (-8), $ c_fontColor, $ font, substr ($ rndstring, 3, 3 )); Imagettftext ($ im, mt_rand (15,17), mt_rand (-8), 54, mt_rand (19,22), $ c_fontColor, $ font, substr ($ rndstring, 9,3 )); Imagerectangle ($ im, 0, 0, $ x_size-1, $ y_size-1, $ black ); Header ("Pragma: no-cachern "); Header ("Cache-Control: no-cachern "); Header ("Expires: 0rn "); // Output a specific image format with a priority of gif-> jpg-> png If (function_exists ("imagejpeg ")) { Header ("content-type: image/policrn "); Imagejpeg ($ im ); } Else { Header ("content-type: image/pngrn "); Imagepng ($ im ); } ImageDestroy ($ im ); Exit (); } Else { // GD is not supported. Only the English letter ABCD is output. $ _ SESSION ['securimage _ code_value '] = "abcd "; $ _ SESSION ['securimage _ code_value_last '] = ''; Header ("content-type: image/policrn "); Header ("Pragma: no-cachern "); Header ("Cache-Control: no-cachern "); Header ("Expires: 0rn "); $ Fp = fopen ("data/vdcode.jpg", "r "); Echo fread ($ fp, filesize ("data/vdcode.jpg ")); Fclose ($ fp ); Exit (); } ?> |