title: Using PHP sessions in jQuery/HTML/Ajax
body: <p>After a successful login attempt my php script starts a session like this:</p>
  
  <pre><code>    session_set_cookie_params(1800,'/','www.mydomain.com',true);
      session_start();
      header("location:mainpage.html");
  </code></pre>
  
  <p>Now my questions are:</p>
  
  <ul>
  <li>How can I save my user-id to my session for further use?</li>
  <li>Would it be sufficient to add these 3 code snippet to keep my sessions alive in a jQuery Mobile page:</li>
  </ul>
  
  <p>mysession.php:</p>
  
  <pre><code>     &lt;?php
       session_set_cookie_params(1800,'/','www.mydomain.com',true);
       session_start();
       ?&gt;
  </code></pre>
  
  <p>somewhere in mainpage.html:</p>
  
  <pre><code>    function getHttpRequestObj()
      {
          if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
              return new XMLHttpRequest();
          }
          else
          {// code for IE6, IE5
              return new ActiveXObject("Microsoft.XMLHTTP");
          }
      }
  
      function callSession(id)
      {
      var xmlhttp = getHttpRequestObj();
      xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
          {
          document.getElementById(id).innerHTML=xmlhttp.responseText;
          }
        }
      xmlhttp.open("GET","mysession.php",true);
      xmlhttp.send();
      }
  </code></pre>
  
  <p>And then in the outmost div (name='main') in mainpage.html</p>
  
  <pre><code>      $(document).ready(function() {
  callSession('main');
  });
  </code></pre>