I am trying to create a captcha code image using php gd:
$im = imagecreatetruecolor(100, 25); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); $imgstring=$_GET['captcha']; $font = 'RAVIE.TTF'; imagettftext($im, 15, 0, 10, 20, $black, $font, $imgstring); header('Content-Type: image/png'); imagepng($im); imagedestroy($im);
The GET value is sent using ajax as follows:
var randstring; function Captcha() { randstring = Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, 5))).toString(36).slice(1); $.ajax({ url: 'test_image.php', data: {'captcha' : randstring}, method: 'GET', success: function (data){ console.log(data); }, error: function (){ alert('Error'); return false; } }); }
HTML:
<img src="test_image.php">
Although it does not give errors, the image is not generated. Yes, the request will reach the php script, I already checked, but something is blocking the creation of the image ...
UPDATE Actually an image is created and an ajax request is also sent. But in the test_image.php script, $ _GET ['captcha'] (request) is not recognized, so it just displays an empty line in this image, although there is an image, but without a line.