Forum Moderators: coopster
For example, I have a bunch of variables that store info about the currently logged-in user. Then I would like to store some session variables about the environment, but keep them separate from the user session variables. This would enable me to do things like loop through JUST the user session variables, or JUST the environment session variables. Also, I could destroy all user session variables, without affecting the environment variables.
At the moment, I'm just prepending some sort of identifier to each variable key, such as 'user_' to every user session key (e.g. 'user_firstname') to keep them identified, but I think this is pretty stupid, and assume multiple sessions can be kept separate... I just couldn't find any helpful information out there. Can I do this with session names?
I don't want to have to worry about giving every session variable a unique prefix, for fear of deleting unrelated session variables. For example, on a form I might like to have a temporary session variable called 'email', which I would delete at the end of the form. But there's already an 'email' session variable for the currently logged-in user, so I have to call it 'user_email' to identify it separately. It would be nice to store the temporary form data in a separate session that I can just delete outright and not worry about the other sessions.
A session table can simply consist of a couple of columns. One can hold the id the rest the session specifics. The information stored in the db can be serialized.
You can check the sessions reference in php.net
So what I did was just store everything in arrays in $_SESSION.
e.g.
$_SESSION['user'] = array(); // Stores all user session vars
$_SESSION['something-else'] = array(); // Stores other stuff
And this way I can partition the session variables and just unset one of those arrays.