I am implementing a user authentication system for my site. I am using an open source library that supports 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 this information?
It is very difficult for me to access custom variables, because I need to first create an object to access them:
$userObj = $_SESSION['userObject'];
$userObj->userId;
instead of just accessing the user id, like this, as usual I will store the user id:
$_SESSION['userId'];
Is there any advantage to storing a bunch of user data as an object instead of just storing them as separate SESSION variables?
ps. The library also stores several variables inside the user object (identifier, username, date, email address, last db user request), but I really do not want to have all this information stored in my session, I just want to save the user ID and name user.
source
share