Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,

I've had a problem which I've now solved but I feel that my solution is not a good one and would like to try and understand a better way of doing it.

 

A user gets a quote and the information is stored in a session. In order to save that quote to the database I require the user to register. This information also went into a session. If the user logged in first and then got a quote then everything was fine. If the user got a quote first and then either registered or logged in then the process of logging in overwrote the session data stored for their quote. Somehow I was structuring my sessions incorrectly. I have tweeked the structure of my users session array and now it worked, which is great. But I'm being reactive rather than understanding how sessions should be structured.

 

So in my example above what is the correct way to store mulitple information in a single session. If it were arrays you would just give the arrays different names:

 

$users = array(user_id => 1, first_name => Paul....etc);

$curtain_quote = array(drop => 100, width => 200....etc);

 

But $_SESSION is a fixed name (isn't it). How do you assign multiply information to this single array? Can $_SESSION be treated as the name of a multidimensional array. Not sure if the syntax is strictly correct but something like:

 

$_SESSION = array ('users' => $users = array(user_id => 1, first_name => Paul....etc), 'curtain_quote' =$curtain_quote = array(drop => 100, width => 200....etc), etc etc;

 

Would this be correct?

 

Cheers

Paul

Link to comment
Share on other sites

 Share

×
×
  • Create New...