Here is some very simple code for sessions
ini_set('session.cookie_lifetime', 0);
session_start();
echo session_id();
var_dump($_SESSION);
$_SESSION["name"] = "test";
I load the page once.
I then comment out
#$_SESSION["name"] = "test";
I hit reload and can the $_SESSION variables.
If I completely close the browser and start it up, I expect the $_SESSION variable to be completely empty.
Instead I see that "name" is still part of the $_SESSION variable.
Please alter this code so that it empties the $_SESSION if I close the browser. When I open it again, the $_SESSION variable should be empty.
Not possible. PHP tracks sessions based on a cookie set in the browser, so if your browser persists cookies across separate launches, then your PHP session will continue as well. You could set your session expiry lower, but that applies to all sessions.
PHP has absolutely no concept of whether or not your browser has been closed between two requests.