Session and Cookies in Codeigniter?

0


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

$this->session->set_userdata('key','value');


to get data from the session


$this->session->userdata("key");


to destroy session data

if we destroy particular data then we can use

this->session->unset_userdata('some_name');
$this->sessio->sess_destory();

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.



Cookie:-

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.


set_cookie('key',value,time);

get_cookie('key')

delete_cookie('key')

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



Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)