Facebook连接提供一个重定向循环 [英] Facebook-connect gives a redirect loop

查看:144
本文介绍了Facebook连接提供一个重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请,我需要帮助。我在处理这个问题1个月!!



我想实现Facebook连接登录到我的网站,使用PHP和php-sdk 3.1.1。几句话,我的代码工作离线(在本地主机上),但不在线,导致导致重定向循环(在Chrome上)太多:错误310(net :: ERR_TOO_MANY_REDIRECTS):重定向太多。



这是我的代码:



1 /我加载Facebook连接SDK和初始化:

  require'src / facebook.php'; 
$ facebook = new Facebook(array(
'appId'=>'209633612480053',
'secret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
));请注意,我在facebook-developmentper页面上创建了两个应用程序,一个用于离线测试,另外一个用于离线测试。其他用于在线测试。在测试时,我确定在两对appId / secret(在线和离线)之间切换正确。所以这不是坏的facebbok-connect init的问题。



2 /我尝试获取用户信息:

  $ uid = $ facebook-> getUser(); 

如果($ uid)
{
/ *
*获取用户信息。
* /
$ user = $ facebook-> api('me /');
print_r($ user); //显示用户信息。
}
else
{
/ *
*重定向到FB登录URL以允许访问。
* /
$ loginURL = $ facebook-> getLoginURL();
echo'< script> top.location.href = \。$ loginURL.'\< /脚本>;
}

这么简单:如果用户ic连接到Facebook,所以显示它信息,否则,重定向到Facebook登录页面以允许访问。



它的工作非常正常,但在线,我得到一个镀铬错误:

 此网页有重定向循环
网页https://www.facebook.com/dialog/oauth?client_id=209633612480053&redirect_uri=http %3A%2F%2Fwww.bluward.com%2Foauth%2Ffacebook& state = 551f60cd4be6cd8ed1622f8168a5219a#_ = _导致重定向太多。清除此网站的Cookie或允许第三方Cookie可能会解决问题。如果没有,可能是服务器配置问题,而不是您的计算机的问题。

一些额外的信息:在线,我使用1and1主机提供商,并确保拥有相同的服务器配置比离线服务器(这是一个MAMP Pro),我上传了sams php.ini文件。



请,如果有人有想法或类似的问题,我很乐意提供帮助。



提前感谢您的帮助。



更新:



我更新了我的代码,专注于有问题的行,所以不要重定向到Facebook登录页面,我显示重定向网址,所以我只是必须点击登录:

  $ uid = $ facebook-> getUser(); 

如果($ uid)
{
/ *
*获取用户信息。
* /
$ user = $ facebook-> api('me /');
print_r($ user); //显示用户信息。
}
else
{
/ *
*重定向到FB登录URL以允许访问。
* /
$ loginURL = $ facebook-> getLoginURL();
echo $ loginURL; //< - 这里我更改了显示登录的代码URL
}

什么我注意到,Facebook是无限的重定向到我的脚本页面。



所以,为什么facebbok正在重定向到我的脚本页面而不给我用户信息?



请问,任何想法?

解决方案

问题,在我的情况下,我必须从SDK编辑base_facebook.php:

  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,
);

我手动添加的最后两个选项。


Please, I need help. I'm dealing with this issue for 1 month!!

I would like to implement facebook connect login to my website, using PHP and php-sdk 3.1.1. In few words, my code works offline (on localhost) but not online which results in "Too many redirect loop (on Chrome)": Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

Here is my code:

1/ I load facebook connect SDK and init it:

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

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

2/ I try to get user info:

  $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's as simple as that: If user ic connected to facebook, so display it's information, else, redirect to facebook login page to allow access.

IT WORKS PERFECTLY OFFLINE, 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.

Some additional information: Online, I use 1and1 host provider, and to be sure to have the same server configuration than offline server (which is a MAMP Pro), I uploaded the sams php.ini file.

Please, if someone has an idea, or get a similar problem, I'll be glad to have help.

Thank you in advance for all help.

UPDATE:

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

  $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
  }

What I noticed is that facebook is infinitely redirecting to my script page. Only code parameter on URL bar changes.

So, why facebbok is redirecting to my script page without giving me user info?

Please, any idea?

解决方案

I had this problem, in my case I had to edit base_facebook.php from the 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,
);

The last two options I added manually.

这篇关于Facebook连接提供一个重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆