title: Handling PHP session while using jquery ajax form submit
body: <p>I am working on a web site with login registration functionality.I have implemented the login registration part with reference and forum help,but now I am facing problem with the PHP session.This is my ajax form submit:</p>
  
  <pre><code>   $.ajax({
                      type: "POST",
                      url: "userLogin.php",
                      data: "eid="+eid+"&amp;pwd="+pwd+"&amp;rememberme="+remember,
                      dataType: "html",
                      success: function(msg){
                          if($.trim(msg)!="error")
                          {
                              $("#user_status", window.parent.document).html("Welcome "+msg+"&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='forum/logout.php'&gt;Logout&lt;/a&gt;");
  
                              if(window.parent.document.getElementById('post_user_name'))
                                  $("#post_user_name", window.parent.document).html("&lt;strong style='color:#333333;'&gt;"+msg+"&lt;/strong&gt;");
  
                              parent.$.fancybox.close();
                          }
                          else{
                              $('#error_common').html("Invalid ID or password.Please try again");
                              $('#error_common').show();
                              return false;
                          }
                      }
                  });
  </code></pre>
  
  <p>This is the PHP code:</p>
  
  <pre><code>             if(isset($_POST['eid']) &amp;&amp; isset($_POST['pwd']))
            {     
                  $userObj = new Model_Users();
                  $username= return_fetched_value($_POST['eid']);
                  $password= md5(return_fetched_value($_POST['pwd']));
                  $getUserDetails = $userObj-&gt;getUserValueByUserNameAndPassword($username,$password);
                  /*print_r($getUserDetails);
                  exit;*/
  
                  if(count($getUserDetails)&gt;0)
                  {   
  
                      $_SESSION['username'] = $getUserDetails['uname'];
                      $displayUser=$getUserDetails['uname'];  
                      echo $displayUser;
  
                  }
                  else
                  {
                      //echo "entered here";  
                      echo "error";
                  }
  
            }
            else
            {
              $errorMessage = "You have entered invald username password" ;
  
            }
  </code></pre>
  
  <p>Everything works fine,the user logs in and get the username on the login page as here <a href="http://www.proptiger.com/,but" rel="nofollow">http://www.proptiger.com/,but</a> if I refresh the page the username disappears,but it is still present in the session.I can see it if I do <strong>print_r($_SESSION)</strong>.
  The username has been set using the jquery ajax portion.</p>
  
  <pre><code>        $("#user_status", window.parent.document).html("Welcome "+msg+"&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='forum/logout.php'&gt;Logout&lt;/a&gt;");
  </code></pre>
  
  <p>Which I think is not <strong>persisted</strong>,but still there in the session.I am new to jquery ajax and stuck at this.Any constructive comments  would be helpful.
  Thanks</p>