CodeIgniter Forums
how to use Saving Session Data to a Database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: how to use Saving Session Data to a Database (/thread-31245.html)



how to use Saving Session Data to a Database - El Forum - 06-11-2010

[eluser]my9006ci[/eluser]
how to use a class session, and save it to the database session in accordance with user guide and how to save user_data and whether they can be used for the system log?
Please help the explanation and examples


how to use Saving Session Data to a Database - El Forum - 06-12-2010

[eluser]pickupman[/eluser]
You use the same syntax when using the session library regardless of storage. It's your config file determines where the session is stored. Either way you use:
Code:
$this->session->set_userdata('some_key','This is a string'); //store a value in session
$this->session->userdata('some_key'); //returns 'This is a string';

$this->session->set_flashdata('some_key','Available on the next request page only'); //store a flash variable
$this->session->flashdata('some_key'); //returns 'Available on the next request page only');

Per the user guide you can also pass a multi-dimensional array to set_userdata($array) and the array keys become the session key identifiers, and the values become the text stored in session.