title: Facebook connect not redirecting properly all of sudden
body: <p>Did Facebook just randomly change their API over the last couple of days? I had my site working perfectly with the Facebook API and now all of a sudden it doesn't work at all. No, I haven't changed anything, it literally just decided yesterday to not redirect anymore...it seems to just try to connect a few times and then it displays this page:</p>
  
  <p>"The page isn't redirecting properly
  Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
      *   This problem can sometimes be caused by disabling or refusing to accept
            cookies."</p>
  
  <p>Anyway, here is some code to wrap your heads around :P (yes, I do actually have my real app id's and such in place)
  This is the fbLogin_member.php file which is where you're directed after clicking on the Login link:</p>
  
  <pre><code>$app_id = "my id #";
  $app_secret = "my secret id";
  $my_url = "http://www.sitedomain.com/confirmlogin_fb_member.php";
  
  if (empty($code)) {
      $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id ."&amp;redirect_uri=". urlencode($my_url) ."&amp;scope=email";
      echo "&lt;script&gt; top.location.href='". $dialog_url ."'&lt;/script&gt;";
  }
  
  $code = $_REQUEST['code'];
  </code></pre>
  
  <p>Here is the confirmlogin_fb_member.php file:</p>
  
  <pre><code>//if user denies access to your website, take him to your manual login page    
  // if ($_GET['error']) {
      // header("Location: memberlogin.php");
      // exit;
  // }
  
  require_once('config/dbconfig.php');
  
  $app_id = "my id #";
  $app_secret = "my secret id";
  $my_url = "http://www.sitedomain.com/confirmlogin_fb_member.php";
  
  
  $code = $_GET['code'];
  
  $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
      . $app_id . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;client_secret="
      . $app_secret . "&amp;code=" . $code;
  
  
  // request access token
  //use curl and not file_get_contents()
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_URL, $token_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  $access_token = curl_exec($ch);
  curl_close($ch);
  
  $graph_url = "https://graph.facebook.com/me?" . $access_token;
  
  // request user data using the access token
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_URL, $graph_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  $temp_user = curl_exec($ch);
  curl_close($ch);
  
  //decode the json array to get user data
  $user = json_decode($temp_user);
  
  //store user data
  $u = $user-&gt;name;
  $e = $user-&gt;email;
  $fb_id = $user-&gt;id;
  $username = $user-&gt;username;
  $picture = 'https://graph.facebook.com/'. $fb_id .'/picture';
  
  //check if user has already signed up before
  $insert = true;
  $result = mysql_query("SELECT * FROM members") or die(mysql_error());
  
  while ($row = mysql_fetch_array($result)) {
      //if username already exists, do not insert
      if (($row['name'] == $u) &amp;&amp; ($row['userType'] == "facebook_user")) {
          $insert = false;
      }
  }
  
  // Random Password Generator
  $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  srand((double)microtime()*1000000);
  $i = 0;
  $pass = '' ;
  
  while ($i &lt;= 7) {
      $num = rand() % 33;
      $tmp = substr($chars, $num, 1);
      $pass = $pass . $tmp;
      $i++;
  }
  // end generator
  
  // if new user, insert user details in your mysql table
  if ($insert) {
      mysql_query("INSERT INTO members(name, fb_username, password, email, profile_pic, userType) VALUES('$u', '$username', '$pass' , '$e', '$picture', 'facebook_user')") or die(mysql_error()); 
  }
  
  //login user
  if (!session_start()) session_start();
  $_SESSION['in'] = true;
  $_SESSION['userName'] = $u;
  $_SESSION['userType'] = "facebook_user";
  $_SESSION['userEmail'] = $e;
  
  //take user to his/her homepage
  header("Location: layout.php");
  </code></pre>
  
  <p>Lastly, here is the top of layout.php where the Facebook API session is called:</p>
  
  <pre><code>session_start();
  require_once('config/dbconfig.php');
  require_once('facebook/facebook.php');
  
  if (isset($_REQUEST['logout'])) {
      unset($_SESSION['in']);
      unset($_SESSION['userName']);
      unset($_SESSION['userType']);
      unset($_SESSION['userEmail']);
      session_destroy();
      header("Location: layout.php");
  }
  
  $session = $_SESSION['in'];
  if (!$session) {
      $login = '&lt;a href="fbLogin_member.php" class="fbLogin"&gt;Login with Facebook&lt;/a&gt;';
  
      $tooltipMsg = '&lt;p&gt;You must &lt;strong&gt;Log in&lt;/strong&gt; to vote.&lt;/p&gt;';
  } else {
      $sessionUser = $_SESSION['userName'];
      $result = mysql_query("SELECT * FROM `members` WHERE name = '$sessionUser'") or die('Query failed: ' . mysql_error() . "&lt;br /&gt;\n$sql");
  
      if ($result) {
          $sessionRow = mysql_fetch_array($result);
          $sessionUserid = $sessionRow['memberid'];
      }
  
      if ($sessionRow['userType'] == "facebook_user") {
          $facebook = new Facebook(array(
                                      'appId'  =&gt; 'my app id #',
                                      'secret' =&gt; 'my secret id',
                                      'cookie' =&gt; true
                                  ));
  
          // $session = $facebook-&gt;getSession();
          $user = $facebook-&gt;getUser();
  
          $me = null;
          // Session based API call.
          if ($user) {
              try {
                  $me = $facebook-&gt;api('/me');
              } catch (FacebookApiException $e) {
                  // error_log($e);
              }
          }
      }
  </code></pre>
  
  <p>It just boggles my mind that it has worked fine for a couple weeks, and now when I come back home from being gone a day and a half it doesn't work. Any help would be appreciated, even if there is some other things wrong you see with my coding (this is my first attempt with the facebook api) :)</p>