In CodeIgniter or any other framework session is used to store information (in variables) and used it through out the application.
To store data in session first of all we need to initialize the session.
In PHP we initialize the session by simply write the session_start(); function.
But in CodeIgniter We can do that by executing the following line in constructor.
In php we simply use $_SESSION super global variable to add value to a session.
Same thing can be done in CodeIgniter as shown below.
set_userdata() function takes two arguments. The first argument, session name, is the name of the session variable and here any value is the value assign to the session. We can use set_userdata() function to pass array to store values as shown below.
In PHP, we remove the data by using unset() function.
But in CodeIgniter we use unset_userdata() function that will remove data from session.
If you want to remove more that one value and a array data then you can use the same function unset_userdata().
After set a data to a session we also retrieve it for our use. Userdata() function will be used for this purpose.