Welcome Guest, Not a member yet? Register   Sign In
How to set and retrieve session in CodeIgniter 3.0
#1

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
Reply
#2

please paste full error message
Reply
#3

(This post was last modified: 05-28-2015, 11:44 PM by hkachhia.)

(05-28-2015, 11:32 PM)gadelat Wrote: please paste full error message

A PHP Error was encountered

Severity: Notice
Message: Undefined index: isLoggedIn
Filename: dashboard/Main.php
Line Number: 28
Reply
#4

Well, what's Line 28? It cannot be $this->session->userdata('isLoggedIn');
Reply
#5

(This post was last modified: 05-29-2015, 01:28 AM by hkachhia.)

(05-29-2015, 01:23 AM)gadelat Wrote: Well, what's Line 28? It cannot be $this->session->userdata('isLoggedIn');

yes, it is  on Line 28     $this->session->userdata('isLoggedIn');

I already Worked in CodeIgniter 2.2.0 but had issue in CodeIgniter 3.0
Reply
#6

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
Reply
#7

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.
Reply
#8

(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
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.

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB