0

I have got a piece of .php to create a captcha for a contact form. The captcha generates fine when I test it on my local xampp testing server. However now that I have upload the site to my remote server the captcha only generates the background but no verification code. I just can't figure out why. Here is the php below

<?php

session_start();

header("Expires: Tue, 01 Jan 2013 00:00:00 GMT"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';

for ($i = 0; $i < 5; $i++) 
{
    $randomString .= $chars[rand(0, strlen($chars)-1)];
}

$_SESSION['captcha'] = strtolower( $randomString );


$im = @imagecreatefrompng("captcha-background.png"); 


imagettftext($im, 20, 5, 10, 30, imagecolorallocate ($im, 0, 0, 0), 'larabiefont.ttf', $randomString);

header ('Content-type: image/png');
imagepng($im, NULL, 0);
imagedestroy($im);

?>  
user3260707
  • 81
  • 1
  • 9

1 Answers1

0
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';

for ($i = 0; $i < 5; $i++) 
{
    $randomString .= $chars[rand(0, strlen($chars)-1)];
}

$_SESSION['captcha'] = strtolower( $randomString );
$im = imagecreatetruecolor(80, 24);
$bg = imagecolorallocate($im, 22, 86, 165);
$fg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 5, 5,  $randomString, $fg);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
$captchaUrl = 'captchaImage.png';
imagepng($im,$captchaUrl);
imagedestroy($im);

Use this code for create captcha image

Shorabh
  • 190
  • 2
  • 9