我已经阅读了这个论坛以及遍布整个网络的有关Firefox浏览器为何无法通过单击按钮刷新PHP中创建的CAPTCHA图像的信息。我的脚本可以在Edge,Chrome,Safari,Brave中使用,但不能在Firefox中使用,实际上我已经构建了3种不同的脚本,并且所有脚本都发生了相同的事情。我不是很擅长编码,并且已经按照教程学习了,但是我已经重写了这些脚本,试图使它们正常工作,但是在FF中却没有。
如果我使用浏览器自己的刷新功能,Firefox将刷新图像,并且它将加载一次图像,仅此而已。
有人可以帮助我,并为为什么发生这种情况提供帮助。
实际测试页
http://www.nailit.nz/REFRESH%20CAPTCHA%20ONLY/index_danials_version.php
感谢您的协助 克里斯
带有图像页面的按钮
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#test").load("captcha_image.php");
return false;
});
});
</script>
</head>
<body>
<div id="test">
<p>This is the first bit of content</p>
</div>
<button id="btn">Change Image</button>
</body>
</html>
图片src页面
<img src ="captcha_CHRIS.php">
使用PHP创建图像页面
<?php
session_start();
header("Pragma:no-cache");
$chars = "0123456789abcderghijklmnopABCDEFGHIJKLMNOPQRSTUVWXYZ";
$random_string = '';
for($i = 0; $i < 5; $i++){
$random_string .= $chars[rand(0, strlen($chars)-1)];
}
$_SESSION['captcha'] = strtolower($random_string);
$captcha_img = imagecreatefrompng("assets/captcha_background.png");
/* Below first numbers desc: 1)font size. 2)rotation angle. 3)left position. 4)top position */
imagettftext($captcha_img, 24, -8, 8, 32, imagecolorallocate($captcha_img, 255, 114, 0),"assets/SedgwickAve-Regular.ttf",$random_string);
header("Content-type: image/png");
imagepng($captcha_img, null, 0);
imagedestroy($captcha_img);
?>
答案 0 :(得分:0)
这可能是由于firefox的缓存机制所致。您需要将缓存设置为false
Uri uri = new Uri("http://example.com/%2F");
ForceCanonicalPathAndQuery(uri);
using (WebClient webClient = new WebClient())
{
webClient.DownloadData(uri);
}
void ForceCanonicalPathAndQuery(Uri uri){
string paq = uri.PathAndQuery; // need to access PathAndQuery
FieldInfo flagsFieldInfo = typeof(Uri).GetField("_flags", BindingFlags.Instance | BindingFlags.NonPublic);
ulong flags = (ulong) flagsFieldInfo.GetValue(uri);
flags &= ~((ulong) 0xC30); // Flags.PathNotCanonical|Flags.QueryNotCanonical
flagsFieldInfo.SetValue(uri, flags);
}
在ajax中,您可以尝试这种方式
cache: false
答案 1 :(得分:0)
正如亨利玛特所说,这可能是Firefox缓存。
尝试:
i/Shield/Lock
,等待几秒钟,然后单击“清除cookie和站点数据...”,然后选择域如果以上方法均无济于事,请尝试通过Web服务器或Cloudflare禁用缓存。这是我发现的一些快速链接:
希望对您有帮助,如果您解决了问题,请告诉我!