验证码图像不再显示

问题描述 投票:0回答:1

我刚刚安装了我的XAMPP并在那里粘贴了我的OLD htdocs和mysql目录。除了一件事,一切都很完美。我在PHP中创建了一个关于输入验证码的表格。它曾经在以前版本的XAMPP中正常工作,但现在我不知道为什么图像不会出现。

这是代码:

<form class="login" method="POST" action="">
    <p class="title">Are you human?</p>
    <div id="captchaimage">
        <img src="generate.php">
    </div>
    <input type="text" name="scr" size="6" placeholder="Write what you see here" autofocus/>
    <a href="http://zite.pouyavagefi.com/helpcenter.php">Can not read the code?</a>
    <input class="submititon" type="submit" value="Submit" name="submit"></input>
</form>

这是generate.php文件:

    <?php 
session_start();
header('Content-type: image/jpeg');

$text = $_SESSION['scr'];
$font_size = 26;
$image_width = 100;
$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);
    $y1 = rand(1, 100);
    $x2 = rand(1, 100);
    $y2 = rand(1, 100);

    imageline($image, $x1, $y1 ,$x2 ,$y2, $text_color);
}

imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text);
imagejpeg($image);
?>

font.ttf文件也正确放置在目录中,代码中没有问题。那么为什么我看不到图像。我还清除了我的浏览器缓存(chrome)并重新启动XAMPP但仍出现同样的问题......

php apache browser xampp captcha
1个回答
0
投票
<!--should this be empty?--><?php 
session_start();
header('Content-type: image/jpeg');

标头调用之前没有输出(session_start也有)。否则它会抛出一个错误,这会破坏传入的图像数据。

© www.soinside.com 2019 - 2024. All rights reserved.