CodeIgniter Forums
How to store "custom session data" in sessions table? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to store "custom session data" in sessions table? (/showthread.php?tid=11729)



How to store "custom session data" in sessions table? - El Forum - 09-21-2008

[eluser]inktri[/eluser]
So I'm using the session class and want to store in the sessions table more than just the IP, session id, etc. How can I store the custom session data such as username, and logged_in in the sessions table? I tried altering the schema so each sessions record has a username field and a logged_in field; however the values of those fields never change accordingly.

Code:
$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '[email protected]',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);



How to store "custom session data" in sessions table? - El Forum - 09-21-2008

[eluser]Dready[/eluser]
You'll find in the wiki ( http://codeigniter.com/wiki/DB_Session/ ) a drop-in replacement for CodeIgniter sessions, that will fit your needs.


How to store "custom session data" in sessions table? - El Forum - 09-21-2008

[eluser]llbbl[/eluser]
its usually not a big deal, storing them in the cookie as long as you don't store a bunch of stuff. you might try encrypting the cookie if your worried about cross site cookie hax.

if you store it in the database, you will still need to set the cookie with the session key, so your going to be using cookies one way or another. setting the cookies helps prevent things like people logging on with different computers in a network, so like you could use your coworkers account if you could successfully duplicate his user agent.