I have a $_SESSION var which stores simple, easily callable identifying information when a user is logged in. Even when a user is not logged in, it logs the last file visited (in case a user logs in, to return quickly to that page).
User Logged in
$_SESSION[$userid,$username,$first_name,$lastPage];
User Not Logged in
$_SESSION[$lastPage];
My chief concerns are security and ease of understanding for future programmers.
So are any of these options viable, or am I missing an option which is more secure, and very easy to understand for programmers?
- Use the $_SESSION var, and access it in classes.
- Use a
sessionWrapperclass to mimic the values in $_SESSION. - Keep only a unique identifier, and perhaps
lastPagein the $_SESSION var. Create asessionWrapperclass that pulls the pertinent information from the database if this unique identifier is given.
Am I missing something here? As I write this I lean closer to option 3 but really appreciate any feedback about best practices here.
$_SESSION['variable'] = ….$_SESSION['loggedIn'] = true? Curious about session security? Go nuts owasp.org/index.php/Session_Management_Cheat_Sheet. PHP specific owasp.org/index.php/…