My captcha code is not working, I am able to bring up the lines at back but the numbers are not visible in the captcha. The code is working perfect on localhost but not on my hosting website.
here's the code:
<?php
session_start();
header('Content-type: image/jpeg');
$text= $_SESSION['secure'];
$font_size =30;
$image_width= 110;
$image_height=40;
$image=imagecreate($image_width,$image_height);
imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
for($x=1; $x<=30; $x++){
$x1 = rand(1,100);
$x2 = rand(1,100);
$y1 = rand(1,100);
$y2 = rand(1,100);
imageline($image, $x1, $x2, $y1, $y2, $text_color);
}
imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.TTF', $text);
imagejpeg($image);
?>
i guess youre missing the font on your webhosting server. try a free one, which is likeley installed on the server or just upload the font to your webhost an set the correct path to the fontfile
I commented that line and i got this warning and notice:
Notice: Undefined index: secure in F:\xampp\htdocs\captcha.php on line 4
Warning: imagettftext() [function.imagettftext]: Invalid font filename in F:\xampp\htdocs\captcha.php on line 23
so first check out the font location. then check out that the $_SESSION['secure'] value and if it's empty check why that session is empty. hope it helps you.
Edited: 1. I saved the code in a php file in my localhost. 2. commneted line that includes header('Content-type: image/jpeg'); cause it set the page mime-type as jpg 3. i read the notice and the warning. Anyway i think your problem is empty session value or check gd is enable in your server.