PHP Session times out after ~30min on IE8

I have a very simple login script that creates a session like:


session_start();
$_SESSION['valid_user'] = $variable;

I am noticing that after ~30 minutes the session times out on Internet Explorer 8, forcing you to log in again. This works fine however in Firefox.

Does Internet Explorer have a 30 minute time out setting or could it be my script?

are you calling session_start(); at the beginning of -every- page, or only when they log in?
(You should be doing the former!)

You can find out if the problem is ie by viewing the http headers that ie sends. No session cookie sent to your server = ie problem. But I really doubt it.

Most likely is that the php garbage collection process is cleaning up your session files. By default, the garbage collector is run randomly, and when it runs, it will delete files older than 24 minutes since last session_start call for that session_id. You should not expect any idle session to last longer than your session.gc_maxlifetime setting. And if it’s a shared webserver, other users can often muck with this unless you create your own session directory.

Anyway, to debug, do some logging.


$id = $_COOKIE[session_name()];
$file = session_save_path() . '/sess_' . $id;
if ($id && !file_exists($file)) {
    $message = "$id\
";
    file_put_contents('mylog.txt', $message, FILE_APPEND);
}

You might want to put more info into the log. But, this will get you started. If you start getting entries, it means that a browser has sent a session cookie, but, there is no session file corresponding to it. probably garbage collected.