1

The situation:
I have multiple QR-codes; these all have the same format, i.e., they refer to a website, BUT since each QR-code is unique, the URL also contains the unique QR-id. So QR-code id 1 contains a reference to URL, e.g.: https://mywebsite.com/processqr.php?id=1 QR-code id 2 contains a reference to URL: https://mywebsite.com/processqr.php?id=2 etc.

The problem:
When you first scan QR-code id 1, the browser of the mobile phone displays the webpage belonging to QR-code id 1. That works. When you then scan - with the same mobile phone - QR-code id 2, the webpage of QR-code id 1 is again shown!!

However, this behavior does not occur with every mobile phone. With an iPhone 6 (using IOS 12.4.8 and Safari) the situation described above does not occur. With an iPhone 5SE, iPhone 8 or Android, this situation does occur.

What I have tried:
(1) Since this looks like a caching issue, I have tried disabling the cache of the generated webpage using the solution described here: How do we control web page caching, across all browsers? Unfortunately that does not solve this problem...

(2) When you clear the cache - of mywebsite.com - on the mobile it again works; but only one time. If you then try to scan QR-id 3, it then shows the webpage of the previous QR-id scanned. However, clearing the cache manually after each scan is not a practical solution.

(3) The Apache webserver access log file does list the correct website URL contained in the QR-code. So on the server side the URL is received correctly, the correct webpage is then generated, but somehow the mobile phone keeps displaying the previous webpage.

Any thoughts? Thanks in advance!

Regards, Erik

Erik
  • 49
  • 1
  • 5
  • Ignoring scanning for a bit, can you visually confirm on those devices that when you go from page with `id` of 1 to page with `id` of 2 that a _different_ or the _same_ QR code is being display? – Chris Haas Aug 14 '20 at 17:42
  • I can confirm that two different QR-codes are present. Note that this does work on an iPhone 6. – Erik Aug 15 '20 at 14:10
  • Hey, out of curiosity did you end up finding a solution to this problem? – Johan Ie Jan 21 '21 at 01:14
  • No, I'm afraid not. I did find out that the issue is not related to QR-codes. It also occurs when you only use the URL's in the browser of the mobile phone. It seems that for some reason the browser only looks at the path name portion of the URL and not the parameters after it; i.e. ?id=1. Otherwise I cannot explain why the two different URL's both show the same webpage... – Erik Jan 22 '21 at 10:33

1 Answers1

0

I have found the issue, and a solution, but I cannot completely explain it.

The code that causes the issue looks similar to this:

if (!isset($_SESSION['sessionkey'])) {
        $_SESSION['sessionkey'] = session_id();
        $_SESSION['QRid'] = $_GET['id'];
}

// use QR-id via $_SESSION['QRid']

The problem is that when you scan a different QR-code the second time, the $_SESSION['sessionkey'] still has the value from the first scan, so $_SESSION['QRid'] also has the value it got at the first scan, thereby messing things up.

I solved this by adding another clause in the if-statement:

if (!isset($_SESSION['sessionkey']) or $_GET['id'] != $_SESSION['QRid']) {

What I do not get is why the code sometimes works and sometimes not. The original code works perfectly on an iPhone 6 and iPhone 11, but it fails for an iPhone 8...

Erik
  • 49
  • 1
  • 5