dennismonsewicz Posted January 25, 2010 Share Posted January 25, 2010 <?php header( "Content-type: image/png" ); session_start(); function createImg() { $num_chars=6;//number of characters for captcha image $characters=array_merge(range(0,9),range('A','Z'),range('a','z'));//creating combination of numbers & alphabets shuffle($characters);//shuffling the characters $captcha_text=""; for($i=0;$i<$num_chars;$i++) { $captcha_text.=$characters[rand(0,count($characters)-1)]; } $_SESSION['captcha'] =$captcha_text;// assigning the text into session $captcha_image=imagecreatetruecolor(140,30); $captcha_background=imagecolorallocate($captcha_image,225,238,221);//setting captcha background colour $captcha_text_colour=imagecolorallocate($captcha_image,58,94,47);//setting cpatcha text colour imagefilledrectangle($captcha_image,0,0,140,29,$captcha_background);//creating the rectangle imagettftext($captcha_image,20,0,11,21,$captcha_text_colour,$captcha_text); imagepng($captcha_image); imagedestroy($captcha_image); } echo '<img src="' . createImg() . '" alt="Captcha" />'; ?> The above just outputs weird characters the screen, such as: �PNG ��� IHDR����������qa!���gIDATh���A � ���1�y`� H�s4�SФc��p������`R�I&�`R�I&�`R�I&�`R�I&�`R�I&�`R�I&�`R�I&���l{\����IEND�B`� Any ideas why this is happening? Thanks! Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted January 25, 2010 Author Share Posted January 25, 2010 Nevermind folks, thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.