Storing user info in Session using an Object vs. normal variables

Posted by justinl on Stack Overflow See other posts from Stack Overflow or by justinl
Published on 2011-01-04T01:46:47Z Indexed on 2011/01/04 1:53 UTC
Read the original article Hit count: 580

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about session