I would like to store the variable in the session currently i am tryin like this but not working.
In Controller
I consider storing my session data in a controller. So this is how you should go about storing and retrieving session data
1.Use autoload in your config.php files. It saves you time and load time
autoload['libraries'] = ('session);
2.In your controller.php create an array to store your session data.
$new_data = array( 'username' => 'martin', 'email' => 'someone@martin.com', 'user_logged => TRUE );
$this->session->set_userdata($new_data);
$username = $this->session->userdata('username');
For further reference visit codeigniter user_guide/sessions