title: PHP Session vs. DB Lookup
body: <p>I've read conflicting information on this topic, so I'm hoping with the scenario I put forth, one plan will be more ideal than another.</p>
  
  <p>In my case there are "users" who have access to "groups" that are comprised of "sections". Each section can have a different permission level based on how the user is configured. So I may be an "admin" for a section, while my coworker is "basic".</p>
  
  <p>After logging in, a user would choose the group they want to manage/view. My original plan was to lookup the user/group/section/permisison info and store in an array in session like...</p>
  
  <pre><code>$_SESSION[group_id][sectioin_id]['permission'] = 7; // 1+2+4 (R+W+X)
  </code></pre>
  
  <p>Then when they go to a page, I could look up what group they're in, see what section page their on, and display the appropriate info based on their permissions.</p>
  
  <p>Alternatively, I could build a DB lookup script to check this info, but it will have to lookup across multiple joined tables and parse the results for EACH PAGE. This seems inefficient to me, but from what I'm reading about how sessions are written for each page, it may not be so.</p>
  
  <p>Thanks for any ideas/suggestions.</p>
  
  <p>// ---- more info on possible session size</p>
  
  <p>Right now a group has a max of 5 sections, with up to three pieces of data. The max size of the session currently would be something like:</p>
  
  <pre><code>$_SESSION[1][1]['permission'] = 7;
  $_SESSION[1][1]['type'] = 'paid';
  $_SESSION[1][1]['expires'] = '2011-08-01';
  $_SESSION[1][2]['permission'] = 7;
  $_SESSION[1][2]['type'] = 'free';
  $_SESSION[1][3]['permission'] = 7;
  $_SESSION[1][3]['type'] = 'paid';
  $_SESSION[1][3]['expires'] = '2011-08-01';
  $_SESSION[1][4]['permission'] = 7;
  $_SESSION[1][4]['type'] = 'paid';
  $_SESSION[1][4]['expires'] = '2011-08-01';
  $_SESSION[1][5]['permission'] = 7;
  $_SESSION[1][5]['type'] = 'free';
  </code></pre>
  
  <p>This would be the case where section's 1,3,4 are at a paid level and 2,5 are at the free version.
  Is that too much session stuff to track per login?</p>