#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,671
    Rep Power
    171

    Is it a better practise to store user data in session or retrieve from database


    Hi;

    When a user logs in, is it a better practise to store user data in session (on successful log) or store only customer id in a session and retrieve from database on each page load based on that id?

    Thanks
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    If you load the data into the session from the database when a user logs in, and the user then updates their personal information in the database this does not automatically get synced to the session - you would have to write this in manually.

    So, with this in mind, it's your call - you're using CI, how/what does this support in this respect?
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Sessions tend to be faster than databases (especially if you use a memory store like memcache for sessions) so I recommend them. You do have to note, like Northie said, that updating user records means refreshing the session, but that should be easy.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,671
    Rep Power
    171
    Originally Posted by Northie
    If you load the data into the session from the database when a user logs in, and the user then updates their personal information in the database this does not automatically get synced to the session - you would have to write this in manually.

    So, with this in mind, it's your call - you're using CI, how/what does this support in this respect?
    Good point. Thanks

IMN logo majestic logo threadwatch logo seochat tools logo