title: Why my FB app loops forever in IE?
body: <p>I have a Facebook app which loops forever when run in IE. In other browsers it works fine.</p>
  
  <p>I need your help to debug this, but before that I need to mention how I have implemented it.</p>
  
  <p>FB recommends that when user tries to access the app we should redirect the user to the app authorization page. From there FB will redirect (using 302 code) to an url which we like. In this case I ask FB to redirect to my app's url with a flag <code>appLogin=1</code> in query string. But along with that FB attaches a really long param <code>code</code> in the query string which is quite ugly. So, in this case I put a flag <code>LoggedIn</code> in my PHP session and redirect the user back to the app url using a JS code <code>window.top.location.href = &lt;app url&gt;</code>. This cleans the url in the location bar.</p>
  
  <p>This works fine in Firefox and Chrome, but in IE <code>LoggedIn</code> flag is missing from the session after the code redirects from <code>appLogin</code> stage. In fact it seems the PHP session has reset in this case. This confuses my app into believing that this is an initial request so it redirects user to the authorization page.</p>
  
  <p>I hope the above makes sense. Really appreciate any insight.</p>
  
  <p><strong>Update1:</strong></p>
  
  <p>As requested. Here goes the code snippet.</p>
  
  <pre><code>$reset = false;
  $topRedirect = true;
  
  if (isset($_REQUEST['appLogin'])) {
      resetSession();
  }
  session_start();
  
  $facebook = new Facebook(array(
    'appId' =&gt; $AppId,
    'secret' =&gt; $AppSecret,
    'cookie' =&gt; true,
  ));
  
  if (isset($_REQUEST['appLogin'])) {//Comes here when appLogin is set, i.e. we have just been redirected here from OAuth (authorization) page.
  
      if (isset($_REQUEST['error'])) {
          if ($_REQUEST['error_reason'] === 'user_denied') {
              $msg = "You need to click on 'Allow', so that this App can fetch the data needed.";
              $allowRetry = true;
              include('error.php');
          }
      }
  
      $authToken = $facebook-&gt;getUserAccessToken(); //This was originally protected. Made public for my purpose.
      if ($authToken === false) {
          //If no user token found and it wasn't even an error then this is totally unexpected.
          $msg = "Totally unexpected error occurred!";
          $allowRetry = true;
          logErr($msg);
          include('error.php');
      }
  
      $_SESSION['LoggedIn'] = 1;
      $reset = false;
      $url = $AppUrl; //We redirect again to clean the url.
      include('redirect.php');
  } else {
      if (!isset($_SESSION['LoggedIn']) || $facebook-&gt;getUserAccessToken() === false) {
          //If we are here then this is an initial request.
          $reset = false;
          $url = $OAuthUrl;
          include('redirect.php');
      }
  }
  
  $accessToken = $facebook-&gt;getAccessToken();
  </code></pre>
  
  <p><strong>Update2:</strong></p>
  
  <p>The included files - redirect.php and error.php invoke <code>exit()</code> when their processing is done. So the code after them won't get executed.</p>