Are there any reasons not to want to use a multi dimensional SESSION array to store temporary user data?
3 Answers
Unless you're storing megabytes worth of data, it should make negligible performance difference how you choose to make use of the $_SESSION array, as it just gets serialized to a string. Personally, I'm a fan of creating a Session class and saving an instance of it in $_SESSION['session']. Something like this:
<?php
class Session
{
private $something;
public function Session()
{
// Constructory things
}
// Methods to your heart's content
}
if (session_id() == '')
{
session_start();
}
if (empty($_SESSION['session']))
{
$_SESSION['session'] = new Session();
}
$session =& $_SESSION['session'];
?>
Save that in a file called session.php, and then just require 'session.php' at the top of every php file where you need access to the session, and access the session through the $session variable defined at the bottom.
Comments
None that i can think of.
If you are worried serialize it first into a string.