2
votes

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.

4
how about showing some code? for two controllers that have the problem maybe? also do you have any custom auto-loaded libraries, plugins that might be resseting the session?!ifaour
Do you have a live site you can have someone else test, to rule out your local environment?jondavidjohn
Code above. Only one controller involved. No custom auto-loaded libraries. This is working on a live site but a different domain.sehummel
It's the Javascript redirect! Anyone have any thoughts on why?sehummel
ummm, so the redirect is to a different domain?ifaour

4 Answers

2
votes

It is true while working on local host. Specify the cookie_domain to localhost. This will retain all the session data on page redirects.

1
votes

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.

0
votes

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 :)

0
votes

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.