title: PHP-SDK too many redirects
body: <p>I'm using the <a href="https://github.com/facebook/facebook-php-sdk" rel="nofollow noreferrer">PHP-SDK</a> for Facebook and got the example to work on my localhost. However, when building a script on a server the script stays quite busy with redirecting from my script to facebook and back. (Error: Fout 310 (net::ERR_TOO_MANY_REDIRECTS):)</p>
  
  <p>It seems that many more people have got this issue (<a href="https://stackoverflow.com/questions/8771833/not-getting-access-token-or-too-many-redirects">here</a>, <a href="https://stackoverflow.com/questions/10200749/url-has-too-many-redirects-facebook-wont-be-able-to-scrape-this-url-until-the">here</a>, <a href="https://stackoverflow.com/questions/10573199/facebook-connect-gives-a-redirect-loop">here</a>, <a href="http://www.zymic.com/forum/lofiversion/index.php/t24244.html" rel="nofollow noreferrer">here</a>). Though, I can't find a clear answer what goes wrong. </p>
  
  <p>Redirect to facebook (response 302):</p>
  
  <pre><code>https://www.facebook.com/dialog/oauth?client_id=166958180001271&amp;redirect_uri=http%3A%2F%2Fdomain.com%2Fscripts%2FGateway.php%3Faction%3DAllowFacebookAccessAction%26app%3D14&amp;state=0dbc178a375595da4751265a7147c01e#_=_
  </code></pre>
  
  <p>Redirect to mydomain (response 302):</p>
  
  <pre><code>http://domain.com/scripts/Gateway.php?action=AllowFacebookAccessAction&amp;app=14&amp;state=0dbc178a375595da4751265a7147c01e&amp;code=AQD-dTeyns0OWpGb_PzfHxUy2iRmpc1XgP6Q24DDRX8MiRTE10lV-b-aSNIlOLVHk576vRs3H8Pf9n0kGwU827MrkzUCUoQGFGEQBkkOJnCy9zb6hZs7TVBsKL2iSuZIhDjLsCOPeKy3zfb37Q6LGhtMICCdB_IQAvU0uRvAkSAX8tdVJ65PEv8imx-2yvLaMoGJleZwKogh7m03vlhV8hJk#_=_
  </code></pre>
  
  <p>Part of the code that creates this issue</p>
  
  <pre><code>...            
      $facebook = new FacebookApi(array(
              'appId' =&gt; $app-&gt;getProperty('apiKey'),
              'secret' =&gt; $app-&gt;getProperty('secretKey'),
          ));
      $user = $facebook-&gt;getUser();
      if (!$user) {    
          header('location: ' . $facebook-&gt;getLoginUrl());
          exit;
      }
  ...
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I ruled out that its a server setting. I was able to run the original example script on that server. </p>