title: Redirect to home page after successful login using AJAX
body: <p>I have a login page that works fine, but it doesn't redirect after the SESSION is set. I want my ajax to display errors if nessesary and redirect if the SESSION was set.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>AJAX:
  
  &lt;script&gt;
          function loginUser(){
                           $.ajax({
                              type:"post",
                              url:"process.php",
                              data:$("#formsubmit").serialize(),
                              success:function(data){
                                  if($session == true){
                                      window.location.href="http://www.example.com";    
                                  }
                                  $("#result").html(data);
                               }
                            });
                      }
      &lt;/script&gt;
  
  PHP:
  if (sha1($passcheck) === $record['password']){
              $_SESSION['user']= $_POST['username'];
              mysqli_query($db_con, $updateIP);
              if($record['admin'] == 1){
                  $_SESSION['admin1'] = $_POST['username'];
              }
          }else{
             echo "&lt;font color='red'&gt;Username or password was invalid.&lt;/font&gt;";
        }
  if(isset($_SESSION['user'])){
      $session = true;
      echo $session;
  }else{
      $session = false;
      echo $session;
  }
  ?&gt;
  </code></pre>
  
  <p>I did not include my whole PHP script or my whole HTML page, because the rest is not useful.</p>