I have run into an interesting situation.
There is a QR Code that gets generated from a PHP functionality (phpqrcode/qrlib.php - for those who are aware of it - SO thread phpqrcode QR Code Resize when displayed directly in browser)
The beauty of that functionality is that when a user opens the php page in a browser (like example.com/qr-page.php), it perfectly displays the QR code as an image.
The way to use it on any other webpage is to "source" that webpage as an image in the standard HTML <img>
tage, like <img src='qr-page.php' />
It perfectly displays the QR code as an image.
However, the issue is that sometimes the dynamically generated QR code gets INCORRECT input, so it fails to generate the QR code image. It then displays the standard "Missing Image" icon (like follows):
Still OK till here.
But then, the user CORRECTs the input, & possibly because of image caching, the standard "Missing Image" icon continues to display even after several refreshes of the webpage with the correct inputs.
Then, if the user visits the same webpage on another device, the QR code image gets displayed correctly. Therefore, it seems to be a caching issue.
On the PHP page, I've tried to use the following to prevent caching:
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
But the problem persists.
Any idea how to get this working please?
The code: show-qr-code.php (this calls the image)
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// Set the text content which will be used to generate the QR code in qr-page.php
"$text4qrcode = "abc";
// Now include the image sourced as php page
echo "<img src='qr-page.php?a=".rand(100,9999)."' alt='Scan missing ' />";
// other code
qr-page.php (this creates the QR code image)
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// Include the qrlib file
include './phpqrcode/qrlib.php';
QRcode::png($text4qrcode); // this generates the image of QR code using $text4qrcode variable value