How to set & unset session variable in codeigniter ?
The session class in CodeIgniter allows the user to maintain a user’s “state” and track their activity while browsing the website. The session can be initialized using the library and auto-loaded in the environment using the following command.
Set the session variable: Session indexes can be assigned using key-value pairs. A particular key can be assigned to a value using the assignment operator. The value may be a string, key, or even an array.
$_SESSION['key'] = value;
Session id is 9 New session id is -8
The session value can also be assigned using the set_userdata() method in CodeIgniter. This method takes a key as the first argument and the. next is the value to be assigned.
set_userdata ('key' , value)
Multiple key-value pairs can also be added at the session index in CodeIgniter, indicated by the following code snippet.
Array ( [id] => 5 [name] => yash )
Unset the session variable: The session variable can be unset by assigning it to a NULL value. This destroys the value stored at this key value.
$_SESSION['ey'] = NULL
Old session : Array ( [id] => 5 [name] => yash ) New session? :
Please Login to comment...