title: Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects. Using PHP SDK for facebook
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13065649/php-sdk-too-many-redirects">PHP-SDK too many redirects</a>  </p>
  </blockquote>
  
  
  
  <p>Am trying to save sessions of facebook login to database and using localhost as HOST(using PHP SDK for facebook). Below is my code.</p>
  
  <pre><code>&lt;?php
  
  require_once 'facebook/facebook.php';
  require 'config/fbconfig.php';
  require 'config/functions.php';
  
  $facebook = new Facebook(array(
              'appId' =&gt; APP_ID,
              'secret' =&gt; APP_SECRET,
              ));
  
  $user = $facebook-&gt;getUser();
  
  if ($user) 
  {
    try {
      // Proceed knowing you have a logged in user who's authenticated.
      $user_profile = $facebook-&gt;api('/me');
    } catch (FacebookApiException $e) {
      error_log($e);
      $user = null;
    }
  
      if (!empty($user_profile )) {
          # User info ok? Let's print it (Here we will be adding the login and     registering routines)
  
          $username = $user_profile['name'];
           $uid = $user_profile['id'];
             $email = $user_profile['email'];
              $user = new User();
          $userdata = $user-&gt;checkUser($uid, 'facebook',     $username,$email,$twitter_otoken,$twitter_otoken_secret);
          if(!empty($userdata)){
              session_start();
              $_SESSION['id'] = $userdata['id'];
      $_SESSION['oauth_id'] = $uid;
  
              $_SESSION['username'] = $userdata['username'];
      $_SESSION['email'] = $email;
              $_SESSION['oauth_provider'] = $userdata['oauth_provider'];
              header("Location: home.php");
          }
      } else {
          # For testing purposes, if there was an error, let's kill the script
          die("There was an error.");
      }
   } else {
      # There's no active session, let's generate one
      $login_url = $facebook-&gt;getLoginUrl(array( 'scope' =&gt; 'email'));
              header("Location: " . $login_url);
   }
  ?&gt;
  </code></pre>
  
  <p>home.php looks like below..</p>
  
  <pre><code>&lt;?php
  
  //Always place this code at the top of the Page
  session_start();
  if (!isset($_SESSION['id'])) {
      // Redirection to login page twitter or facebook
      header("location: index.php");
  }
  else
  {
  echo '&lt;h1&gt;Welcome&lt;/h1&gt;';
  echo 'id : ' . $_SESSION['id'];
  echo '&lt;br/&gt;Name : ' . $_SESSION['username'];
  echo '&lt;br/&gt;Email : ' . $_SESSION['email'];
  echo '&lt;br/&gt;You are login with : ' . $_SESSION['oauth_provider'];
  echo '&lt;br/&gt;Logout from &lt;a href="logout.php?logout"&gt;' . $_SESSION['oauth_provider'] .     '&lt;/a&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>But the browser(chrome) is throwing below error</p>
  
  <pre><code> Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
  </code></pre>
  
  <p>I have tried clearing all cookies but to no avail. Let me understand how to handle this error, or if there is a code to be changed. Also i have tried looking into forums for the error, but they were not so explanatory, for it might be am new to this area.</p>