I developed a system with PHP and am having problems with session variables ($ _SESSION). A page assigns a value to a session variable and calls another page. This other page receives the value correctly only on the first call. From the second call, the value of the session variable remains the same, even though it was updated with a different value. If you perform a refresh of the page in the browser, the value of the variable displays the correct value. However this value is what will remain until a new refresh is executed in the browser. This occurs in both Chrome and Internet Explorer. I have no idea why this is occurring or how to resolve or circumvent the situation.
I've created two pages that faithfully reproduce the problem:
//PAGINA 1:
header('Cache-Control: no cache');
session_cache_limiter('private_no_expire');
session_start();
echo '<br>ANTES';
if (isset($_SESSION['var1']))
echo '<br>var1=' . $_SESSION['var1'];
else
echo '<br>var1 não existe';
echo '<br>';
$_SESSION['var1'] = 'T';
echo '<br>conteudo var1 alterado para T<br>';
echo '<br>DEPOIS';
if (isset($_SESSION['var1']))
echo '<br>var1=' . $_SESSION['var1'];
else
echo '<br>var1 não existe';
echo '<br>';
echo '<br><a href="pagina2.php"><input type="button" value="Vai p/ pagina 2"></a>';
//PAGINA 2:
header('Cache-Control: no cache');
session_cache_limiter('private_no_expire');
session_start();
echo '<br>ANTES';
if (isset($_SESSION['var1']))
echo '<br>var1=' . $_SESSION['var1'];
else
echo '<br>var1 não existe';
echo '<br>';
$_SESSION['var1'] = '';
echo '<br>conteudo var1 alterado para NULL<br>';
echo '<br>DEPOIS';
if (isset($_SESSION['var1']))
echo '<br>var1=' . $_SESSION['var1'];
else
echo '<br>var1 não existe';
echo '<br>';
echo '<br><a href="pagina1.php"><input type="button" value="Vai p/ pagina 1"></a>';