How to get the values using session in codeigniter?

Member

by lottie , in category: PHP Frameworks , 21 days ago

How to get the values using session in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by lindsey.homenick , 20 days ago

@lottie 

In CodeIgniter, you can use the Session library to store and retrieve values across different requests. Here is an example of how you can get values using session in CodeIgniter:

  1. First, you need to load the Session library in your controller or model:
1
$this->load->library('session');


  1. To set a value in the session, you can use the set_userdata() method:
1
$this->session->set_userdata('key', 'value');


  1. To get a value from the session, you can use the userdata() method:
1
$value = $this->session->userdata('key');


This will retrieve the value stored in the session with the key 'key'. You can then use this value in your code as needed.


Remember that you need to have the Session library loaded in your controller or model in order to access session data.