Question

Having a hard time implementing a script I came across for a Captcha code. Not too familiar with PHP so any help would be awesome.

Problem: Captcha Image does not show up on the live server, but does on my local server.

Verification File:

<?php
header('Content-type: image/jpeg');

$width  = 90;
$height = 30;
$dir = getcwd().'/fonts/';

$black = imagecolorallocate($my_image, 0, 0, 0);
$angle = rand(0,3);

imagefilledrectangle($image,0,0,399,99,$white);


$my_image = imagecreatetruecolor($width, $height);

imagefill($my_image, 0, 0, 0xFFFFFF);

// adds noise
for ($c = 0; $c < 50; $c++){
    $x = rand(0,$width-1);
    $y = rand(0,$height-1);
    imagesetpixel($my_image, $x, $y, 0x000000);
    }

$x = rand(10,12);
$y = rand(10,15);

$rand_string = rand(1000,9999);
//imagestring($my_image, $font, $x, $y, $rand_string, 0x000000);
imagettftext ($my_image, 22, $angle,10, 27, $black, $dir."arial.ttf", $rand_string);
setcookie('tntcon',(md5($rand_string).'a4xn'));

imagejpeg($my_image);
imagedestroy($my_image);
?>

Contact Form:

<img src="verification.php?<?php echo '<span>'.rand(0,9999).'</span>';?>" alt="Anti spam verification" class="verify" />    
  • The font is located in a root folder titled "fonts"

Thank you for your input everyone.

Was it helpful?

Solution

I would assume your "live" server has display_errors off. That means it won't show you the error about what is going wrong. You need to check the PHP error log. My guess is that GD isn't installed.

It should be in /var/log/apache2 if you are using Apache. If not, you can ask PHP by creating a PHP info file to see what the setup is.

<?php phpinfo();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top