...

View Full Version : PHP image being displayed as ‰PNG



djh101
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);
imagefilledrectangle($image,0,0,399,99,$white);
imagettftext ($image, 30, 0, 10, 40, $color, $dir."arial.ttf", $_SESSION['random_code']);
header("Content-type: image/png");
imagepng($image);
?>

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

Fumigator
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.

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

djh101
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.

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

http://www.white-hat-web-design.co.uk/articles/php-captcha.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum