Skip to content
Advertisement

CodeIgniter is generating multiple sessions in the database. Why?

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement