Welcome Guest, Not a member yet? Register   Sign In
Session on Database being lost
#1

[eluser]Paulodemoc[/eluser]
Hello guys, I am having trouble using CI's Session for some reason. I started using database sessions, it solved a lot of my problems. But now, something odd seems to be happening. If I put the session to expire after 10 seconds, then it works fine, after 10 seconds I have to login again. But if I put it to expire after 7200 (2 hours), sometimes it expires after 2 hours, sometimes after 40 minutes of idleness, sometimes after 10... Anyone know what might be causing this?

This is my session config on the config file:

Code:
$config['sess_cookie_name'] = 'ccm_session';
$config['sess_expiration'] = 7200;
$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;
#2

[eluser]bretticus[/eluser]
Off the top of my head, I notice you have the following enabled:

Code:
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;

So, just to start, off the top of my head, ISP http proxies or possibly even AJAX calls.
#3

[eluser]Paulodemoc[/eluser]
match_useragent was FALSE and I still was getting the problem. I just recently changed it to TRUE.
#4

[eluser]slowgary[/eluser]
It's possible that your IP is changing. You've got $config['sess_match_ip'] = TRUE; This means that if your IP address doesn't match the one in the database, your session cookie gets destroyed and you'll be issued a new session cookie.

Another thing to check is that the time is set correctly on your server. Sometimes this can cause issues where your session is always invalid.

EDIT: Question answered before I could submit my post! Keep in mind that computers on the internet may use multiple IPs per session, so matching by IP may not be the best practice for your application (although if you were writing an app to run on a local network or something, it may be desirable).
#5

[eluser]bretticus[/eluser]
There are countless posts here with "session lost" in the title or similar. I suggest searching for "session lost." One of the most recent posts was similar to your problem and got lots of responses. Also, there is a sticky thread ab out sessions and cookies you might want to read. Unfortunately, dealing with sessions and cookies is not likely to have a magic answer someone can just give you. We can ask the questions, but you have to move the discussion along and do the footwork along the way.

Good luck.

What about ISP proxies? Is this just an issue for you or for your users abroad?
#6

[eluser]Paulodemoc[/eluser]
I understand that and I try to give as much information as I have. I still get lost sometimes on this forum, and I posted this 'cause I did a search and found lots of posts that had nothing to do with what I wanted to know. If there was any other similar post, I did'n see it.
About the ISPs, that isn't a problem around here. I will check, just to be sure, but at least here on my machine the IP was being changed.
#7

[eluser]bretticus[/eluser]
I understand also. But really, you need to research the problem and then ask questions where you have gaps. Seriously, take my advice on searching the forum. It will be the quickest way to resolve your problem. As I said, this type of question has been asked so often, there is a sticky post.

EDIT: My bad, it's not sticky. Sorry, but still lots of questions about this. Read this one for example. I dunno if it has your answer but I'm sure it has lots of suggestions for you to try.




Theme © iAndrew 2016 - Forum software by © MyBB