[UPHPU] using $_SESSION to store a user object

Aaron Luman aaron.luman at gmail.com
Fri May 27 18:11:51 MDT 2011


Hey all,

I posted this question a while ago to stackoverflow but didn't get any bites.  I'm curious about security, performance, etc issues in how I have planned out a site I am putting together.  Background, the project is to create something similar to blackboard (minus all the suck).  This is primarily being done as a learning experience, but if we end up liking the project enough we might try to convince some of the teachers here to adopt it.

Each page load contains some data related to every class that they are currently enrolled in (the nav bar) and we are trying to avoid having to pull all that data from the database on every page load.  My current plan is to store the basic data (what is used on most pages) inside a user object that is stored in $_SESSION.  It would be structured something like:

teacher Object
(
    [teaching] => Array
        (
            [0] => course Object
                (
                    [id] => 1
                    [name] => relativity
                    [teacher_id] => 2
                    [semester_id] => 1
                )

            [1] => course Object
                (
                    [id] => 2
                    [name] => physics
                    [teacher_id] => 2
                    [semester_id] => 1
                )

        )
    [taking] => Array
        (
        )
    [id] => 2
    [user_name] => teacher
    [fname] => Albert
    [lname] => Einstein
    [display_user_details] => Array
        (
            [id] => Student ID
            [name] => User Name
            [fname] => First
            [lname] => Last
            [email] => Email Address
            [phone] => Phone Number
            [address] => 
        )
)

The question is, is storing this object in the $_SESSION array good practice?  Or is it better to pull the data fresh from the database on each page load?

the stackoverflow page is: http://stackoverflow.com/questions/6067075/php-performance-questions-on-storing-user-object-in-sessions

Thanks for your input,
Aaron


More information about the UPHPU mailing list