CodeIgniter DB Session problems: sess_expire_on_cl

2019-04-11 23:37发布

问题:

I've encountered a very odd problem with CI's session when stored in the DB. I'm using sessions to store information about whether or not a user is logged in on my site. For some reason, a friend of mine from Lithuania (I mention the country in case it's relevant somehow) could not log in. When I monitored the session table, it seemed like she was creating a new session for each page she went to. She tried using various browsers, but the same problem occurred regardless of browser. No one else has this problem (all other testers are outside of Lithuania).

Here's the odd thing: I was able to fix her problem by setting sess_expire_on_close = TRUE. I'm guessing that can't possibly be the fix, but whenever I set it back to FALSE, the problem comes back.

My other problem is that I seem to occasionally lose session data, which means the user gets logged off. Not sure what causes this. I'm going to post a different SO question for it, but thought it might be useful to mention it here.

回答1:

What version of CodeIgniter are you using? CI 2.1.1 at release had a session bug whereby sessions weren't getting deleted from the database, along with other problems. If you're on 2.1.1 (the only version affected with the issues), I'd recommend upgrading to 2.1.2 and trying again.



回答2:

Is your ci session configuration set to match ip address? If so, your friend might be on a 3G mobile connection and maybe constantly changing her ip address while surfing... Just a guess.



回答3:

I remember few years ago there was similar problem in one of the UK internet providers. Their IP changed almost, if not every request. I believe that session is related with IP. So everytime she visit another page she is assigned to a new session.

Check her IP everytime she visit your page.