Problem: in the code below when I move from page from sandbox1 to sandbox2 the new value of $_SESSION[page_name] is not being passed on and reverts back to the initial value of index. If after entering the page I reload the page the new value seems to magically show up. Is there something wrong with the code? Could you explain why the new value of $_SESSION is not propagating?
Page index.php
<?php
session_start();
$_SESSION['page']="index";
echo "This page: ".$_SESSION['page']."<br><br>";
?>
Page sandbox1.php
<?php
session_start();
echo "From page: ".$_SESSION['page']."<br>";
$_SESSION['page']="Sandbox1";
echo "This page: ".$_SESSION['page']."<br><br>";
?>
Page sandbox2.php
<?php
session_start();
echo "From page: ".$_SESSION['page']."<br>";
$_SESSION['page']="Sandbox2";
echo "This page: ".$_SESSION['page']."<br><br>";
?>
On loading index.php it outputs:
This page: index
as expected.
Hyperlink from index.php to Sandbox1 output
From page: index
This page: Sandbox1
(new value $_SESSION['page']) as expected.
Hyperlink from Sandbox1 to Sandbox2 output:
From page: index
($_SESSION revert to value index) expected to see
From page: sandbox1
This page: Sandbox2
(new value)as expected.
Additional information PHP version 5.3. Register global is set to "OFF"
On sandbox1 and sandbox 2, move
session_start()above the line that reads