2

I have a site which does a few ajax calls on page load. For some reason, CodeIgnitor is inserting 4 sessions (I'm assuming one for each ajax call) as you load the page. I'm storing the sessions in the database.

I'm pretty sure there should only be one session per browser. Firefox seems to generate only one; other browsers seem to create a whole bunch of sessions. Multiple sessions for the same user are giving me some serious authentication problems.

Why is this happening? How can I stop it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
CodeChap
  • 4,132
  • 6
  • 30
  • 40
  • because of amny users is browsing the site – Mostafa Elkady Mar 13 '10 at 15:22
  • no - all four have the same IP address. – CodeChap Mar 13 '10 at 15:26
  • Can you list the actual problems you are getting? I have seen this in the past but usually due to being logged out and visiting the site, it generates a blank generic session. Also update your question and include your CONFIG cookie parameters. – Jakub Mar 18 '11 at 16:08
  • I found an answer that worked for me from this page: https://stackoverflow.com/questions/14472869/codeigniter-session-data-lost-after-redirect Copied here as well: > If you are working in CI 3.x and just upgraded your server php version > to php 7.x > > Go to system/libraries/Session/session.php at Line no 281 and replace > ini_set('session.name', $params['cookie_name']); by > ini_set('session.id', $params['cookie_name']); – Dan Feb 08 '19 at 10:41

6 Answers6

7

I know the discussion took place while ago, but somebody might find this useful.

By now I've used CI session without storing its data in database. Today I decided to give it a try and immediately run across the same problem: CI was generating new session in every page load.

I checked my server time, timezone, my cookie etc. - everything I could find as a tip on forums - with no result. Then decided to debug the CI Session class myself.

Long story short, it turned out that my user_agent field in my session table was too small - VARCHAR 50 - which cuts the original user_agent string - hence CI doesn't find my session and generates onother one. I just increased the user_agent field size to 200 and everything works like a charm.

I forgot to mention that I use Mac OS X Lion.

Again, hope this will help somebody.

peterh
  • 11,875
  • 18
  • 85
  • 108
vlad
  • 546
  • 6
  • 5
1

Check the date / time on your client OS, and on your server.

I know its too late, but maybe someone finds this page while looking for the answer...

I think it happens because CI sets an expiration time on the cookie containing the session id and if the time difference between the server and client is higher than the expiration time the cookie gets old and the server will generate a new session for the client on every request. Never took the time to figure out the exact mechanism, but happened to me several times, and this fix always worked.

1

I've found this topic with same problem: on every page CI generates new session. Possible solution: remove underscored from site name ( NOT "my_test_site.com", but "my-test-site.com"). At least, this helped in my situation.

0

Check your config.php file and make sure the cookie options are properly filled out. If they are not it cant track the user and it will gen a new session on every page load.

Tom Schlick
  • 2,298
  • 18
  • 26
  • $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 3600; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = TRUE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300; – CodeChap Mar 13 '10 at 21:21
  • Multiple sessions only occur in safari, IE8, have not checked with chrome yet. FF produces a single session entry. – CodeChap Mar 13 '10 at 22:47
0

Check the date / time on your client OS, and on your server.

I had the same situation and confirm the solution as a fix

Tihomir Mihaylov
  • 805
  • 7
  • 18
-1
$config['cookie_domain'] = "example.com";

Use your domain name in this snippet.

TRiG
  • 10,148
  • 7
  • 57
  • 107
thuclh
  • 169
  • 1
  • 2
  • 5