Session and Cookies in Codeigniter?


A session is a persistent object that is used to retain data of an application after server response under browser cookie.

Session data can be accessed into multiple web pages directly hence it is also called a global variable of PHP.

In Codeigniter session has been defined under the predefine library hence first we load the session from the session library under autoload.php or constructor of controller.

before use session encryption key should be set on the config.php file for security concerns.

Syntax of session

to set data in the session


to get data from the session


to destroy session data

if we destroy particular data then we can use


We should always set sessions under the login page and they should be verified under the dashboard page. A session is used to provide internal page security.


It is used to provide a client-side state management option under any web application, the cookie is used to store data under the browser cookie directory after response.

It stores data in text-format hence cookie is unsecure.CI provides a Cookie helper to store data under the cookie.

Register helper under autoload.php or Controller Constructor.




time is mandatory on cookie to manage cookie data otherwise cookie will be reset the value.

Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)