I have read this forum and all over the net about why Firefox browser fails to refresh a CAPTCHA image created in PHP with a button click. My script works in Edge, Chrome, Safari, Brave but not in Firefox, in fact I have built 3 different scripts and the same thing is happening with all of the scripts. I am not great at coding and have followed tutorials to get here, but I have rewritten these scripts to try and make them work which they do but not in FF.
Firefox will refresh the image if I use the browsers own refresh and it will load the image once but that's it.
Could someone assist me and help with why this is happening.
actual test page
http://www.nailit.nz/REFRESH%20CAPTCHA%20ONLY/index_danials_version.php
Thanks for any assistance Chris
Button With Image Page
<!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>
The Image src Page
<img src ="captcha_CHRIS.php">
The Create Image Page In 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);
?>