The image “http://localhost/Captcha/Captcha.php” cannot be displayed because it contains errors

StackOverflow https://stackoverflow.com/questions/22127585

  •  18-10-2022
  •  | 
  •  

Question

This is my php

<?PHP
$img = imagecreatetruecolor(305,100);

$green = imagecolorallocate($img, 180, 230, 225);
$blue = imagecolorallocate ($img, 10 , 10 , 150);

function random_string($lenght)
{
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ023456789";
srand((double)microtime()*1000000);
$str = "";
$i = 0;
         while($i <= $lenght){
            $num = rand() % 33;
            $tmp = substr($chars,$num,1);
            $str = $str . $tmp;
            $i++;
        }
    return $str;
}

session_start();
$_SESSION['Real'] = random_string(7);


header("content-type: image/png");
imagefill($img,0,0,$blue);

imagettftext($img, 60,0,10,70,$green, "../Captcha/MyFont.ttf",$_SESSION['Real'] );
imagepng($img,"file.png");


imagedestroy($img);
?>

Yesterday this code was working. Then I added no cache in header and because of this it stopped working. Then I deleted thing that I added but nothing. I hundred times checked code from where I wrote this but nothing. Can someone help? Thanks.

No correct solution

OTHER TIPS

comment out content-type line

header("content-type: image/png");

and try running the script again, it will show some error/notice/warnings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top