title: How to set lifetime of session
body: <p>How to set session lifetime in PHP? I Want to set it to forever as long as the request is exist. The request is AJAX. My PHP code that handle AJAX request is:  </p>
  
  <pre><code>// AJAX.php
  &lt;?php    
  session_start();
  
  $_SESSION['counter'] = $_SESSION['counter'] + 1;
  
  header('Content-type: application/json');    
  echo json_encode(array('tick' =&gt; $_SESSION['counter']));
  ?&gt;
  </code></pre>
  
  <p>and the JavaScript:</p>
  
  <pre><code>$(document).ready(function() {            
  function check() {
      getJSON('ajax.php');        
  }
  
  function getJSON(url) {                                
      return $.getJSON(
                  url,
                  function(data) {
                      $("#ticker").html(data.tick);
                  }
             );
  }
  
  setInterval(function() {
      check();
  }, 10000); // Tick every 10 seconds
  
  });
  </code></pre>
  
  <p>The session always resets after 300 seconds.</p>