Search code examples
javascriptphpexecutionscript-tag

PHP files executed twice, but only in Firefox


This is something really weird. I have the following page structure:

index.php

<?php
session_start();
include_once('src/functions.php');
logMe('index');
include_once(TEMPLATES_FOLDER . 'standard/header.php');
[...]
include_once(TEMPLATES_FOLDER . 'standard/footer.php');
?>

header.php

<?php logMe('header'); ?>

<!DOCTYPE html>
<html lang="en">
<head>

    [...]

    <?php if (isset($_SESSION['accountId'])) : ?>
        <script type="text/javascript">
            [...]
        </script>
    <?php endif; ?>

</head>
<body>

[...]

I'm expecting to get 2 log rows, one from index.php and one from header.php (beacuse of the logMe() function).

Now, if I run the page in Firefox (61.0.2), i get 4 logs. If I run it in Chrome (68.0.3440.106), i get 2 logs. So in Firefox it seems it is executing everything twice.

What is even more weird is that if i remove the <script> tag, the problem seems to disappear as Firefox logs only 2 rows. But even if I put back an empty <script> tag, it logs 4 rows! So the key of the problem seems to be this <script> tag, but how can it be??

Moreover, I have a <script> tag also in the footer.php. I then expect to obtain 6 log rows following this behaviour, but I always get only 4. Only if I remove them both (from header and footer) I get the correct behaviour (2 logs).

Does anybody know what is happening?


update

As per raina77ow request, this is the access.log differences:

  • Firefox logged 16 rows while Chrome logged 15 rows
  • Firefox rows that are not in Chrome's log:
    • 127.0.0.1 - - [01/Sep/2018:11:47:49 +0200] "GET /favicon.ico HTTP/1.1" 404 209
    • 127.0.0.1 - - [01/Sep/2018:11:47:49 +0200] "GET /src/lib/toastr/toastr.js.map HTTP/1.1" 304 -
    • 127.0.0.1 - - [01/Sep/2018:11:47:49 +0200] "GET /?pageId=0 HTTP/1.1" 200 4242 (this row is repeated twice, once at the beginning of the log and once at the end)
  • Chrome rows that are not in Firefox's log:
    • 127.0.0.1 - - [01/Sep/2018:11:48:40 +0200] "GET /src/lib/toastr/toastr.js.map HTTP/1.1" 200 25633
    • 127.0.0.1 - - [01/Sep/2018:11:48:40 +0200] "GET /src/lib/bootstrap-3.3.7/css/bootstrap.min.css.map HTTP/1.1" 200 542194

So Firefox is effectively requesting ?pageId=0 twice.


Solution

  • Ok, it seems something got spoiled in my Firefox installation. I tried starting it in safe mode and the problem didn't show. So I made an hard reset on it and now the problem doesn't show anymore.

    Still can't think of any connection between the problem and the <script> tag anyway...