What happens to the $_SESSION array if a PHP session times out in the middle of a request?

php, session, session-timeout

Solution

don't worry about such things. Nothing will happen to the session. It's initialised by `sessioni_start()` and `$_SESSION` will be always available within your script.

Problem

I have always wondered, if a PHP session times out during the middle of executing a script, will the contents of the $_SESSION array still be available until script execution ends? For example: ``` session_start(); if(! isset($_SESSION['name'])) { echo 'Name is not set'; exit; } // imagine there is a bunch of code here and that the session times out while // this code is being executed echo 'Name is ', $_SESSION['name']; // will this line throw an error? ``` Is it practical to copy session variables to the local scope so I can read them later on in the script without having to keep checking for a session time out? Something like: ``` session_start(); if(isset($_SESSION['name'])) { $name = $_SESSION['name']; } else { echo 'Name is not set'; exit; } // bunch of code here echo 'Name is ', $name; ```

Original source