Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda