Session Implementation in Codeigniter 3

How to use or implement sessions in Codeigniter 3 | The function of the session is to store the information needed by the application and can be shared throughout the web page, and this session is stored in a file on the web server environment.

To be able to use the Session class, we need to load the Session.php class library into the controller

$this->load->library(‘session’)
load session
Creating and Accessing SESSION
In native PHP, the function called to run a session is session_start(); at the beginning of the script. In Codeigniter this is not required. If we create a session in native php, we use $_SESSION;

start_session()_;
$_SESSION[‘session_name’] = “value”;
then the case is different if we use the session in codeigniter. We can directly write with the following code:

$this->session->set_userdata(‘session_name’, ‘session_value’)
as an example :

$this->session->set_userdata(‘username’,’administrator’)
example
To access session variables that have been created previously, we can use the following code:

$this->session->userdata(‘username’)
if you want to display the contents of the session variable, just add echo, so it becomes

session->userdata(‘username’);
?>
That is all and thank you 🙂