0

I'm losting the session with CodeIgniter and only in Internet Explorer

I send an AJAX request to my first controller:

/controller/method1

In this method1, I create my session

$this->session->set_userdata('user', 1);

I send a second AJAX request 5 seconds after the first, to another method:

/controller/method2

In this method, I try to show the content of the session user

var_dump($this->session->userdata('user'));

But I got a bool(false) answer.

For information, the session library is autoloaded. In Chrome, that works good.

Do you have any idea to solve this problem?

Thanks

alexmngn
  • 9,107
  • 19
  • 70
  • 130
  • what's the return format of AJAX request? – itachi Dec 03 '12 at 15:43
  • Nevermind I'm just doing a var_dump currently and watch the inspector :) – alexmngn Dec 03 '12 at 15:45
  • CI uses cookies or databases to store session information? If you're using cookies, are you sure you don't have them disabled in IE? If databases, can you peek into the DB to confirm whether the data gets stored or not? – Ayush Dec 03 '12 at 15:45
  • 1
    Are you doing this on your localhost? If so, what is the domain you're using for the cookies? – Brendan Dec 03 '12 at 15:49
  • I'm currently using IE10. CI use cookie in this case to store session information. I'm working in a dev server (no localhost) – alexmngn Dec 03 '12 at 15:56
  • Do the dev domain and the cookie domain in the CI config match? Also, you should be using the format `.domain.ext` (note preceding period). – Brendan Dec 03 '12 at 16:40
  • Be careful with AJAX and sessions. Especially because the order of events isn't guaranteed, one request renewing the session cookie will cause other requests (with the old cookie) to expire your session. This goes for any resource loaded from CI (images, scripts, etc.) – landons Dec 03 '12 at 21:11

2 Answers2

6

Change the 'sess_cookie_name' in config from 'ci_session' to 'cisession'and sess_expiration from 7200 to 84200.

Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101
1

My solution is similar to @sachin-prasad's answer. Only removing the underscore of the sess_cookie_name value will not work. You need to increase the sess_expiration as well.

I tested it in IE 11 and the session works fine.

Esthon Wood
  • 315
  • 3
  • 19