Posts Tagged session
Using Session in CI
Using Session:
For using Session in CI must have to add this following line:
$this->load->library( ’session’ );
Important Note: If you have to use session for different pages, in that case u have to write this same line each and every time. So, better not to use this line, but play with the CONFIG folder.
- go to the location “http://localhost/PROJECT_FOLDER/system/application/config/“
- open the file “autoload.php”
- than rewrite the variable $autoload['libraries'] = array( ‘session‘);
After than should have to assign session value like array:
[array]
( ’session_id’ => random hash,
‘ip_address’ => ’string – user IP address’,
‘user_agent’ => ’string – user agent data’,
‘last_activity’ => timestamp )
Retrieving data from session:
$session_id = $this->session->userdata( ’session_id’ );
Adding Custom Session Data:
$this->session->set_userdata( $array );
Where $array is an associative array containing your new data. Here’s an example:
$sessionArry= array(
‘username’ => ‘Lizee’,
‘email’ => ‘lizee@mysite.com’,
‘logged_in’ => TRUE,
‘usertype’ => ’superAdmin’,
);
$this->session->set_userdata( $sessionArry );
userdata , set_userdata are the library function. So, never and every change those.
Add comment August 21, 2009