1
votes

Access to my developed website is done using facebook connect.

Everything is OK offline, but not online. I get a navigation error (using Chrome) "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%2Faccess%2Flogin_facebook&state=299262ddf89afbf382452df89c9a2ce8&scope=email%2C+user_birthday%2C+user_about_me%2C+user_location%2C+publish_stream&fbconnect=1#= 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.

Here is the PHP code (using CodeIgniter framework):

public function login()
{
  // Get the FB UID of the currently logged in user
  $uid = $fb->getUser();

  // If the user has already allowed the application, you'll be able to get his/her FB UID
  if($uid) {

     try {
        $profile = $fb->api(array(  
            'method'      => 'users.getinfo',  
            'uids'        => $uid,  
            'fields'      => 'uid, first_name, last_name, pic_square, pic_big, sex, birthday_date, current_location, email'
        ));

        // Only the first user.
        $profile = $profile[0];
     } catch (FacebookApiException $e) {
        return false;
     }

     // Do stuff when already logged in.

     return $profile;

  } else {

     // If not, let's redirect to the ALLOW page so we can get access
     redirect($this->getLoginUrl(array(
         'scope'           => 'email, user_birthday, user_about_me, user_location, publish_stream',
         'fbconnect'       =>  1
     )));
  }
}

And depending on the profile info, I check if the user already exists on database, then log him/her, and if not exists on database, signup him/her.

Update:

When I clear Facebook cookies, the redirect to login page is successful, and I'm able to fill email/password.

Unfortunately, when I click "log in" button, I get the same error message as I displayed above.

1
Can you post the full code you are using for auth please.ShawnDaGeek
Here is the code. Thanks for your help.htaidirt
Does somebody know what the error message means really (is it a cookie problem)? Why does this appears only for online test and not on localhost?htaidirt
Updated the question with info from different tests.htaidirt

1 Answers

0
votes

It looks like your using and older version? Here is how i would handle issue with php-sdk 3.1.1 "the most current version".


require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => '135669679827333',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  ));
$user = $facebook->getUser();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
$params = array(
  scope => 'read_stream,publish_stream,publish_actions,read_friendlists',
  //redirect_uri => $url
  );
  $loginUrl = $facebook->getLoginUrl($params);
  echo '<script> top.location.href=\''.$loginUrl.'\'</script>';
};