我们在我们的一个项目中使用了Captcha.php,它在所有浏览器中都会打开,但是我们无法在Google版本22中查看。
我们的Captcha脚本
session_start();
$captcha = new SimpleCaptcha();
$captcha->CreateImage();
class SimpleCaptcha
{
function CreateImage()
{
header("Content-Type: image/jpeg");
$md5 = md5(rand(0,9999));
$pass = substr($md5, 10, 5);
$_SESSION["pass"] = $pass;
$image = ImageCreatetruecolor(100, 20);
$clr_white = ImageColorAllocate($image, 0, 0, 0);
$clr_black = ImageColorAllocate($image, 255, 255, 255);
imagefill($image, 0, 0, $clr_white);
imagefontheight(15);
imagefontwidth(15);
imagestring($image, 5, 30, 3, $pass, $clr_black);
return imagejpeg($image);
imagedestroy($image);
}
}HTML实现
<img src="code/captcha.php" width="100" height="20" alt="Captcha Code"/>我们无法在谷歌Chrome上查看它。所有浏览器都返回相同的图像。
发布于 2018-01-31 06:50:08
添加一个
ob_clean();为我解决了。
完整的例子:
$img = imagecreatefromjpeg('my_image.jpg');
ob_clean();
header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);发布于 2012-10-30 07:15:52
我也面临过同样的问题。刚关掉我的卡巴斯基。现在一切都很好。你也可以试试这个。
发布于 2012-10-30 08:05:48
你说Chrome一直在渲染相同的图像?尝试发送标头,告诉浏览器不要缓存任何内容。
header('Pragma: no-cache');
header('cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 01 Jan 1999 00:00:00 GMT'); https://stackoverflow.com/questions/13097945
复制相似问题