title: php session expires randomly after a few minutes
body: <p>I have a login page/system which has worked correctly for years, leaving the user logged in until he/she either closes the browser window or logs out manually. But lately (starting yesterday) after only a few minutes of inactivity the session cookie/s seems to expire, causing the user to be logged out automatically.</p>
  
  <p>This happens on different browsers and different operating systems, the PHP version is 5.6.29, which has been changed recently (before it was 5.5 and even 5.3). </p>
  
  <p>I create and refresh the session on every page with <code>session_start()</code>. The login script first checks user name and PW and also gets some other user data from the database. These other data are first saved in variables and then written into session variables like </p>
  
  <pre><code>$_SESSION['username'] = $name;
  $_SESSION['usertype'] = $type;
  </code></pre>
  
  <p>The successful login state is saved like this:</p>
  
  <pre><code>$_SESSION['login'] = "ok";
  </code></pre>
  
  <p>On the other pages I check the login state like this:</p>
  
  <pre><code>session_start();
  if(($_SESSION['login'] != "ok") OR ($_SESSION['usertype'] != "xxx")) {
   header("Location: ../login.php"); /* redirects to login page if conditions are not true */
   exit;
   }
  </code></pre>
  
  <p>The login works, and logged-in users can proceed to other pages as long as the do it more or less in constant succession, but <strong>if someone waits a few minutes</strong> before proceding (i.e. without any acitivity), he/she is <strong>logged out</strong> (i.e. redirected to the login page when trying to open another page).</p>
  
  <p>To make it extra-nasty, half of the time it just works as expected, also after half an hour...</p>
  
  <p>Any help would be very much appreciated.</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>Adding <code>ini_set('session.gc_maxlifetime', 3600');</code> and `ini_set('session.cookie_lifetime', 3600); didn't help. I removed it again.</p>
  
  <p>After that I had a look in the error logs and found this:</p>
  
  <blockquote>
    <p>ap_pass_brigade failed with error 103: Software caused connection
    abort</p>
  </blockquote>
  
  <p>(problem is, I don't have access to the server settings - this is on a shared webspace...)</p>