title: jquery mobile app - how to login and store PHP sessions
body: <p>I am having difficulty creating sessions for my mobile application that is written in JQuery.  I want my application to check to see whether a user session exists, if not it redirects user to a login form.  I use ajax to check the login credentials and the user details are returned in JSON format.  </p>
  
  <p>How can I store these JSON variables in a session so that I can access these within my app?</p>
  
  <pre><code>function ajaxPost(LoadUrl, redirect) {
      jQuery.ajax({ 
          type: "POST", 
          url: LoadUrl, 
              data: "email=" + $("#email").val() + "&amp;pw=" + $("#pw").val(),
              complete: function(xhr, statusText){ 
                  if (xhr.status == 401){     
                      alert('Unauthorised');
                  } 
          } ,
  
          success:function(response){ 
                  if(redirect != null){
                      alert(response);
                      &lt;? 
                      //session_start(); 
                      //$_SESSION['user'] = $response;  // this is JSON: {"id":"45454","name":"Joe Blog","username":"joebloguser"} 
                      ?&gt;
                     app.navigate(redirect);
  
                  }
              }
      });                 
  }
  </code></pre>
  
  <p>I have commented out the PHP code that starts the PHP session as this seems to start a session whether or not the ajax call is made, therefore there is always a $_SESSION set, which I obviously do not want.  Can anyone advise on the best way to proceed with this?</p>