View Full Version : PHP image being displayed as ‰PNG

07-02-2010, 12:10 AM
Why won't my image show up? The URL is http://simplyuseless.info/publishare/captcha/captcha.php. My only theory is that GoDaddy's free hosting ad is causing the problem. If so, then I guess it will go away when I get a hosting plan. If not, I'd like to find out the problem BEFORE I get a hosting plan. Oh, and here is my code:

<?php session_start();
$string = '';
for ($i = 0; $i < 5; $i++) {
$string .= chr(rand(97, 122));
$_SESSION['rand_code'] = $string;
$dir = 'fonts/';
$image = imagecreatetruecolor(170, 60);
$black = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 200, 100, 90);
$white = imagecolorallocate($image, 255, 255, 255);
imagettftext ($image, 30, 0, 10, 40, $color, $dir."arial.ttf", $_SESSION['random_code']);
header("Content-type: image/png");

07-02-2010, 12:12 AM
I hate dynamic imaging, but I need a captcha.

07-02-2010, 01:38 AM
Your code works for me, but I had to use $_SESSION['rand_code'] in both locations.

Although, before I copied arial.ttf into the root directory, I got an error msg that looks like the attached image. See how your weird ‰PNG is there after the warning? So my theory is, your script is giving you a warning but you have warnings suppressed so all you're seeing is that bit of bogus output. Try cranking up error reporting and see if you get anything.

07-02-2010, 01:39 AM
With arial.ttf found, I see this.

07-02-2010, 01:53 AM
I think it has to be the GoDaddy ad frame. I've gone through a number of captcha scripts and tutorials and none of them work. I think I'll just start my site off captcha-less and hope it works when I get a hosting plan.

07-12-2010, 01:10 PM
hi just try this example works fine for me...