Facebook-connect gives you a redirect loop

Please, I need some help. I have been dealing with this problem for 1 month!

I would like to use login to enter my site using PHP and php-sdk 3.1.1. In a few words, my code works offline (on the local host), but not on the network, which leads to "Too many redirect cycles (in Chrome)": Error 310 (net :: ERR_TOO_MANY_REDIRECTS): there were too many redirects.

Here is my code:

1 / I load facebook by connecting the SDK and initializing it:

    require 'src/facebook.php';
    $facebook = new Facebook(array(
        'appId'  => '209633612480053',
        'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    ));

Please note that I created two applications on the facebook-developper page, one for offline tests, and the other for online tests. And I'm sure it’s correct to switch between two pairs of appId / secret (online and offline) when testing. So this is not a bad facebbok-connect init problem.

2 / I'm trying to get user information:

  $uid = $facebook->getUser();

  if($uid)
  {
     /*
      * Get user information.
      */
     $user = $facebook->api('me/');
     print_r($user); // Display user info.
  }
  else
  {
     /*
      * Redirect to FB login URL to allow access.
      */
     $loginURL = $facebook->getLoginURL();
     echo '<script> top.location.href=\''.$loginURL.'\'</script>';
  }

It is so simple: if user ic is connected to facebook, display it like that; otherwise, go to the facebook login page to allow access.

THIS WORKS PERFECTLY IN OFF, but online, I get a chrome error:

This webpage has a redirect loop
The webpage at https://www.facebook.com/dialog/oauth?client_id=209633612480053&redirect_uri=http%3A%2F%2Fwww.bluward.com%2Foauth%2Ffacebook&state=551f60cd4be6cd8ed1622f8168a5219a#_=_ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

Additional information: online, I use host provider 1 and 1 and, of course, have the same server configuration as the stand-alone server (which is MAMP Pro), I downloaded the sams php.ini file.

Please, if someone has an idea or has a similar problem, I will be happy to receive help.

Thank you in advance for your help.

UPDATE:

I updated my code to focus on the problematic line, so instead of redirecting to the facebook login page, I display the redirect URL, so I just need to click to log in:

  $uid = $facebook->getUser();

  if($uid)
  {
     /*
      * Get user information.
      */
     $user = $facebook->api('me/');
     print_r($user); // Display user info.
  }
  else
  {
     /*
      * Redirect to FB login URL to allow access.
      */
     $loginURL = $facebook->getLoginURL();
     echo $loginURL; // <-- HERE I CHANGED THE CODE TO DISPLAY LOGIN URL
  }

, , facebook script. code URL.

, facebbok script, ?

, ?

+5
2

, base_facebook.php SDK:

public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.2',
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
);

, .

+5

Chrome, cookie .

facebook Heroku ( js) , chrome, URL- - URL- (: localhost/somedirectory/). , .

index.php https://gist.github.com/2845986

0

All Articles