You'll want to keep in mind that the encoded data isn't written until the script ends, "session_write_close()" is called, or you write the sting to file. So if you assign a value to a session element, call "session_encode()", then change the value later in the same script, the second value will be the one encoded if the encoded data hasn't been written. Also, "session_decode()" will overwrite any elements of the same name that were changed. These will demonstrate:
test.php
session_start();
$_SESSION['test_1'] = 'original_1';
$_SESSION['test_2'] = 'original_2';
$_SESSION['test_1'] = 'new_1';
$sess_encode = session_encode();
$_SESSION['test_2'] = 'new_2';
$fp = fopen('sess_1.txt', 'wb');
fwrite($fp, $sess_encode);
fclose($fp);
session_write_close();
session_start();
$sess_encode = session_encode();
$fp = fopen('sess_2.txt', 'wb');
fwrite($fp, $sess_encode);
fclose($fp);
echo '<a href="test_2.php">click</a>';
test_2.php
session_start();
echo '<pre>';
print_r($_SESSION);
$sess = file_get_contents('sess_1.txt');
session_decode($sess) . '<br />';
print_r($_SESSION) . '<br />';
$sess = file_get_contents('sess_2.txt');
session_decode($sess) . '<br />';
print_r($_SESSION) . '<br />';
echo '</pre>';
/** Displays:
Array
(
[test_1] => new_1
[test_2] => new_2
)
Array
(
[test_1] => new_1
[test_2] => original_2
)
Array
(
[test_1] => new_1
[test_2] => new_2
)
**/
Edit: I don't think I made it real clear, but my point is in there somewhere.
(BTW, I still haven't found the code you used. 🙂 )
Edit: I don't think I made it real clear, but my point is in there somewhere.