Why am I entering the captcha file path in url, it returns inestad binary to image file

why i enter the captcha file path in url, it returns inestad binary to image file but when i use in img tag everything works well. this is my captha file

<?php
  session_start();
  ob_start();
  //$captchaText = strtoupper(substr(md5(microtime()), 0, 5));
  $captchaText=rand ( 100000 , 999999 );
  $_SESSION['captcha'] = $captchaText;

  $image = imagecreate(230, 70);
  $background = imagecolorallocatealpha($image, 239, 239, 239, 1);
  $textColor = imagecolorallocatealpha($image, mt_rand(0, 100), mt_rand(0,255), mt_rand(0,255), 1);
  $x = 25;
  $y = 50;

  for($i = 0; $i < 6; $i++) {
    $fontSize = mt_rand(30, 50);
    $text = substr($captchaText, $i, 1);

    imagettftext($image, $fontSize, 0, $x, $y, $textColor, './captchafont/bnazanin.ttf', $text);

    $x = $x + 17 + mt_rand(0, 10);
    $y = mt_rand(40, 65);
            $textColor = imagecolorallocatealpha($image, mt_rand(0, 255), mt_rand(0,255), mt_rand(0,255), 1);
             $linecolor=imagecolorallocatealpha($image, mt_rand(0, 255), mt_rand(0,255), mt_rand(0,255), 1);
        imageline($image,mt_rand(0, 230) , mt_rand(0, 70) ,mt_rand(0, 230), mt_rand(0, 70), $linecolor);
        imageline($image,mt_rand(0, 230) , mt_rand(0, 70) ,mt_rand(0, 230), mt_rand(0, 70), $linecolor);

  }

  header("Content-type: application/jpeg");
  imagejpeg($image);
  imagedestroy($image);
?>

      

+3


source to share


1 answer


This command may fail, so it sends the output before printing the headers.

imagettftext($image, $fontSize, 0, $x, $y, $textColor, './captchafont/bnazanin.ttf', $text);

      



Make sure the font is in the same folder above inside the "captchafont" folder by referencing this path to your php file.

Try commenting out this line and you should see at least rendering images with some lines on it.

0


source







All Articles