Personally, I do this at the very beginning:
session_start(); session_write_close();
And then you have access to $ _SESSION as read-only. As you can see below, you do not need to copy session variables.
session_start(); //This value will be "The #1 Value!" only the 2nd time you run this echo "<br />myData value1:".$_SESSION['myData']; $_SESSION['myData'] = "Value 2 and 3!"; session_write_close(); echo "<br />myData value2 (read-only):".$_SESSION['myData']; $_SESSION['myData'] = "Value 3 Misleading, and never actually written to the session!"; //But it will affect this value, obviously echo "<br />myData value3:".$_SESSION['myData']; session_start(); //NOTE HOW THE ABOVE LINE WRITES-OVER $_SESSION echo "<br />myData value4:".$_SESSION['myData']; $_SESSION['myData'] = "The #1 Value!"; session_write_close();
source share