Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Why different php session value in Chrome and FireFox?

set a session value to 10 by ajax. In Chrome it will set back to ZERO. Why?? my.php

<?php
session_start();
$_SESSION["temp"] = 0; ?>


<div id="t">$_SESSION["temp"] = <?=$_SESSION["temp"]?> <br></div>
<br><input type="button" value="Plus 5" onclick="javascript:plusn(5);">
<script>
    function plusn(n) {
          $.ajax({
              url: 'myajax.php?n='+n,
              type: 'get',
              async: false,
              success:function(result){
                  $("#t").append(result)
              }
          });
    }
    
    $(document).ready(function() {
        plusn(10); //initial add 10
    })
</script>

myajax.php

<?php
session_start();
$_SESSION["temp"] += $_GET["n"];
exit('$_SESSION["temp"] = '.$_SESSION["temp"].'<br>');
?>

place here: https://cmbody.com/my.php Please use different browsers to check it. Chrome, Edge and Android cell phones get the wrong result; Firefox and iPhone get the correct results. P.S. same condition using COOKIE

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Here's the culprit:

<link rel="shortcut icon" href="#" />

The browser tries to load the favicon from the same URL, as instructed. For that, it performs an additional request to the main PHP script. The differences happen because Firefox uses the cached page and Chrome-based browsers fetch a fresh copy:

Firefox

Chrome

over 4 years ago · Santiago Trujillo Report

0

It works correctly when I send it with a 1000 millisecond delay but this is not a correct solution I will continue to investigate.

setTimeout(()=>{
        plusn(10);
    },1000)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!