Hello,
I'm having some trouble understanding PHP's sessions. First off I am saving session data in a database, I used PHP's session_set_save_handler()
function to define that.
The way I understand when PHP saves the session data to the DB is like so:
If I define some session variables then output some text to the user's browser, I believe the session data is not saved to the DB until after the text is output. Please look at this bit of code:
$_SESSION['username'] = "$username";
//check if session variable set
if($_SESSION['username'] != $username)
{
die('error...');
}
In the code the if statement returns false so die()
never occurs. Also PHP does not write the session data to the DB until after the if statement. What I don't understand is if the session data is not written to the DB yet, how is PHP comparing $_SESSION['username']
to $username
? Is $_SESSION['username']
stored in server memory until the end of the script when session data is written to the DB?
Thank you for your time.