title: Redirect with PHP on Ajax call
body: <p>I have a form which is being submitted through an AJAX call, which is sending to a PHP file called <code>function.php</code>. This is what my AJAX call looks like:</p>
  
  <pre><code>$.ajax({
      type:  'post',
      cache:  false ,
      url:  'function.php',
      data: noteSequence,
      success: function(data) {
          alert(data);
  
          &lt;?php
              if (defined('RESTRICTED')) {
                  if (!isset($_SESSION['logged'])) {
                      header( 'Location: index.php' );
                      exit();
                  }
               }
          ?&gt;
      }
  });
  </code></pre>
  
  <p>On the PHP file I have this if statement. If this is true I want the page to redirect to <code>index.php</code>. A <code>header()</code> isn't working. I tried <code>window.location.href = 'index.php';</code> after the AJAX has been successful, but this is redirecting regardless if the PHP statement is true or not. Currently I was trying to use sessions to redirect the user but thats not working. So can anyone offer a solution please? </p>
  
  <p>PHP code:</p>
  
  <pre><code>if ($rows == 1) { 
      $_SESSION['logged'];
  }
  </code></pre>