CodeIgniter Forums

Full Version: how to use Saving Session Data to a Database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

El Forum

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:
$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.