@jasen
To create and use 2 variables in a session in CodeIgniter, you can follow these steps:
- Load the session library in your controller or autoload it in config/autoload.php:
1
|
$this->load->library('session');
|
- Set the session variables using the set_userdata() method:
1
2
|
$this->session->set_userdata('variable1', 'value1');
$this->session->set_userdata('variable2', 'value2');
|
- Retrieve the session variables using the userdata() method:
1
2
|
$variable1 = $this->session->userdata('variable1');
$variable2 = $this->session->userdata('variable2');
|
- Unset or destroy the session variables when they are no longer needed:
1
2
|
$this->session->unset_userdata('variable1');
$this->session->unset_userdata('variable2');
|
or
1
|
$this->session->sess_destroy();
|
Remember to also configure the session settings in config.php
to make sure the session data is stored and managed properly.