Storing user info in Session using an Object vs. normal variables
- by justinl
I'm in the process of implementing a user authentication system for my website. I'm using an open source library that maintains user information by creating a User object and storing that object inside my php SESSION variable. Is this the best way to store and access that information?
I find it a bit of a hassle to access the user variables because I have to create an object to access them first:
$userObj = $_SESSION['userObject'];
$userObj->userId;
instead of just accessing the user id like this how I would usually store the user ID:
$_SESSION['userId'];
Is there an advantage to storing a bunch of user data as an object instead of just storing them as individual SESSION variables?
ps - The library also seems to store a handful of variables inside the user object (id, username, date joined, email, last user db query) but I really don't care to have all that information stored in my session. I only really want to keep the user id and username.