Reputation: 5568
I'm not sure why, but I am losing my CodeIgniter session data between pages. And the session ID is changing. What could cause this? Shouldn't it be accessible from any page once it is set?
Session data is set here in the configuration page:
<?php $config = array(
'power' => $_COOKIE['power'],
'oemclass4' => $_COOKIE['class'],
'cooling' => $_COOKIE['cooling'],
'beam' => $_COOKIE['beam'],
'wavelength' => $_COOKIE['wavelength'],
'model_no' => $_COOKIE['part']);
$this->session->set_userdata('config', $config);
?>
The user is then redirected to a page with details of their configuration. The session userdata is still there then. Then they are Javascript redirected (window.location) to the login page and the userdata is gone then.
Upvotes: 2
Views: 4619
Reputation: 21
It is true while working on local host. Specify the cookie_domain to localhost. This will retain all the session data on page redirects.
Upvotes: 2
Reputation: 1
It's because config cookie, my session_id change again and again.
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
But I've always a problem... My BDD is updated with local session php but my vars in user_data as been destroyed >< user_data also.
Upvotes: 0
Reputation: 11
I had read somewhere to use 127.0.0.1 in the cookie domain while working on localhost. However, when I changed the cookie_domain to "localhost", the sessions started working. I was planning to switch to Native sessions, but changing to "localhost" worked & I have moved along with CI sessions on localhost.
Upvotes: 1
Reputation: 2735
I had a similiar problem. Please be sure that for example, if the base_url
is set to say, dynamic.dns.com and you test it on localhost typing 127.0.0.1
or localhost, those are all different domains for the browser, this may cause
this issue.
Hope it helps :)
Upvotes: 0