Why is $helper->getSessionFromRedirect() always returning NULL?

时间:2015-05-12 22:58:21

标签: php facebook-php-sdk facebook-login facebook-sdk-4.0

I had this code and it was working fine for months. Suddenly, the production environment stopped working, where <td> is now always returning a $helper->getSessionFromRedirect() value.

login form page (index.php)

NULL

login processing (login.php)

require 'vendor/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;

FacebookSession::setDefaultApplication(123456, 'a1b2c3d4e5');

$helper = new FacebookRedirectLoginHelper('http://domain.com/login.php');
$scope = array('email');
$loginUrl = $helper->getLoginUrl($scope);

echo '<a href="'.$loginUrl.'">Login</a>';

This is working on my test App, but it's not working with my production App ID. The only difference between those are, of course, the App ID and Secret ID values. I already made sure I was following the Facebook instructions. Also, I'm using Facebook PHP SDK 4's last version.

1 个答案:

答案 0 :(得分:1)

经过长时间的诊断,我发现存在差异。由于我使用的是Cloudflare的SSL功能,原始的$helper = new FacebookRedirectLoginHelper('http://domain.com/login.php');请求是使用http:80进行的,但是第二个$helper = new FacebookRedirectLoginHelper('http://domain.com/login.php');是使用https:443进行的...这会返回一个不匹配的类型对Facebook的签名,导致$session变量中的NULL值。

TL; DR 在向fb发出请求时不会混用http和https。