Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Should I store only the user's session id along with the data in a table, or should I store the user's session id in a table and access an array of data from the user's session id?

and why?

What is more efficient?

I will not be generating any reports.

share|improve this question
4  
What framework are you using? All frameworks have built-in solutions for this. –  S.Lott Jul 27 '11 at 23:05
    
Codeigniter. I've been developing for a year, so I'm looking to find out what the industry standard would be. –  Ryan Jul 27 '11 at 23:18
    
What part of this is confusing? codeigniter.com/user_guide/libraries/sessions.html Please be specific, since this seems very clear. –  S.Lott Jul 28 '11 at 1:30
    
Being a purely technical question, this belongs to StackOverflow (please don't repost it there though, it will be automigrated if enough people vote to close it here). –  Péter Török Jul 28 '11 at 7:55
    
This is on-topic here: Programmers.SE is for concept questions about programming. Stack Overflow is for when you actually have code you need help with. –  user8 Jul 28 '11 at 9:43

2 Answers 2

up vote 0 down vote accepted

A few comments either directly about or around your question:

  1. Whatever you do encapsulate the code so you can change it later.
  2. Use whatever is built in to your framework if at all possible.
  3. Generally leaving session data weakly typed (in an array or dictionary) isn't as desirable as making it strongly typed, IMHO. At the very least it discourages people from throwing everything in there without thinking about it. If you have strongly typed session data that might lead you to your table design based on the way you are mapping all your other objects to tables. (Obviously, most frameworks give you weakly typed data, but you could always just store one thing there which gets you to your own application specific session object).
share|improve this answer

The most efficient way to retrieve the session data is to get it from memory, that is from the session object provided by the framework, obviously. Now, if you want to persist information related to a given user (his "profile" in short) in order to remember it between sessions you have several different techniques, such as persisting in/retrieving from:

  • a file with serialized data (one file by user)
  • a "user" table with serialized data (one record by user)
  • a standard database table with the user id and one column for each information

Since you indicated you don't want to generate any report on the users (which can be done with solution 3), you may as well persist it by serializing the data each time the user updates his profile, and deserialize and read it each time he connects to your application. I would store the data in a database because I don't like managing a database AND files, and having files on the web server, but that is personal taste.

Also, the user's password should not be in the session, or if it is the case it should be a hash of the password.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.