【问题标题】:The image “http://localhost/Captcha/Captcha.php” cannot be displayed because it contains errors图片“http://localhost/Captcha/Captcha.php”无法显示,因为它包含错误
【发布时间】:2014-03-02 12:33:39
【问题描述】:

这是我的 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);
?>

昨天这段代码还在工作。然后我在标头中没有添加缓存,因此它停止工作。然后我删除了我添加的东西,但什么也没有。我从我写这个的地方检查了一百次代码,但没有。 有人可以帮忙吗? 谢谢。

【问题讨论】:

  • 假设&lt;?php 之前的空格在实际文件中不存在是否安全?
  • 实际文件中没有。
  • 除了将图像存储在文件中之外,您不会输出任何内容。
  • 但该代码正在输出图像。这段代码来自这里youtube.com/watch?v=CL9AitvjZKg

标签: php captcha


【解决方案1】:

注释掉content-type

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

然后尝试再次运行脚本,它会显示一些错误/通知/警告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    • 2012-03-28
    • 1970-01-01
    相关资源
    最近更新 更多