Function _ Code ( $ _ Code_length = 4, $ _ Width = 75, $ _ Height = 25 ){ For ( $ I = 0; $ I < $ _ Code_length ; $ I ++ ){ $ _ Nmsg . = Dechex (Mt_rand (0, 15 ));} $ _ Session ["Code"] = $ _ Nmsg ; $ _ Img = Imagecreatetruecolor ( $ _ Width , $ _ Height ); $ _ White = Imagecolorallocate ( $ _ Img , 250,250,250 ); Imagefill ( $ _ Img , 0, 0,$ _ White ); $ _ Gray = Imagecolorallocate ( $ _ Img , 196,196,196 ); Imagerectangle ( $ _ Img , 0, 0, $ _ Width -1, $ _ Height -1, $ _ Gray ); For ( $ I = 0; $ I <6; $ I ++ ){ $ _ Md_color = Imagecolorallocate ( $ _ Img , Mt_rand (200,255 ), Mt_rand (200,255 ), Mt_rand (200,255 ); Imageline ( $ _ Img , Mt_rand (0, $ _ Width ), Mt_rand (0, $ _ Height ),Mt_rand (0, $ _ Width ), Mt_rand (0, $ _ Height ), $ _ Md_color );} For ( $ I = 0; $ I <50; $ I ++ ){ $ _ Md_color = Imagecolorallocate ( $ _ Img ,Mt_rand (200,255 ), Mt_rand (200,255 ), Mt_rand (200,255 ); Imagestring ( $ _ Img , 1, Mt_rand (1, $ _ Width -5 ), Mt_rand (1, $ _ Height -5 ),"*", $ _ Md_color );} For ( $ I = 0;$ I < $ _ Code_length ; $ I ++ ){ $ _ Md_color = Imagecolorallocate ( $ _ Img , Mt_rand (0,102 ), Mt_rand (0,102 ), Mt_rand (0,102 ); Imagestring ( $ _ Img , 5, $ I * $ _ Width /$ _ Code_length + Mt_rand (1, 10 ), Mt_rand (1, $ _ Height /2 ), $ _ Session ["Code"] [ $ I ], $ _ Md_color );} Header ("Content-Type: image/PNG" ); Imagepng ( $ _ Img ); Imagedestroy ( $ _ Img );}