How to set and retrieve session in CodeIgniter 3.0 |
Hi,
I am using CodeIgniter 3.0 - I have created Login Module - I have make changes in Config.php as below : $config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
- I have Define Session in autoload.php as below : $autoload['libraries'] = array('database','Session'); $autoload['drivers'] = array(); $autoload['helper'] = array('url'); - I have set session while Authenticate : $this->load->library('Session'); $data_session_set = array('id' => $this->details->emp_reg_id, 'username' => $this->details->username, 'emp_role' => $this->details->emp_role, 'isLoggedIn' => 1); $this->session->set_userdata($data_session_set); - I am trying to fetch Userdata/Session data using below code : $this->session->userdata('isLoggedIn'); But, i am getting below error, A PHP Error was encountered Severity: Notice Message: Undefined index: isLoggedIn
This problem is occur when i am using REST server api with my controller.
Is this problem in REST server ? Or REST server is use only for pass static information
Refer to the database section of the session documentation and see if you missed anything : http://www.codeigniter.com/user_guide/li...ase-driver
I suspect, you haven't created the ci_sessions table in your database. You can do so by running the following query ( refer above link ) : CREATE TABLE IF NOT EXISTS `ci_sessions` ( `id` varchar(40) NOT NULL, `ip_address` varchar(45) NOT NULL, `timestamp` int(10) unsigned DEFAULT 0 NOT NULL, `data` blob NOT NULL, PRIMARY KEY (id), KEY `ci_sessions_timestamp` (`timestamp`) ); for mysql. Alternatively you can use "files" for storing sessions, if this does not work out worst case. (05-31-2015, 01:05 PM)roopunk Wrote: Refer to the database section of the session documentation and see if you missed anything : http://www.codeigniter.com/user_guide/li...ase-driver Thanks for reply I have already mention in my post this problem is occur when i have used REST API. Otherwise its working fine with SESSION. So my question is that How to use session with REST API ? Can you give me small example of Login module using REST API |
Welcome Guest, Not a member yet? Register Sign In |