Page 1 of 1

session/class interaction

Posted: Mon Jun 05, 2006 1:27 pm
by Luke
If I have a class set up and I want my session's array values to be identical to a certain class's properties, what is the best way to set those?
Here is what i have done:

Code: Select all

$auth = new authorize($dbh);
$auth->login("Luke", "pass");
$_SESSION['user_name'] = $auth->user_name;
$_SESSION['pass_word'] = $auth->pass_word;
$_SESSION['user_level'] = $auth->user_level;
There are quite a few more properties than that, but you get the picture.

Posted: Mon Jun 05, 2006 1:45 pm
by Christopher
Why not just store the object in the session:

Code: Select all

$_SESSION['auth'] =& $auth;
The only trick you need to do is make sure that the Auth class is always loaded before session_start() is called (or use autoload)

Posted: Mon Jun 05, 2006 1:52 pm
by Luke
OK, thanks!