简体   繁体   中英

Facebook SDK PHP Redirect loop

When i have no session made it displays the login page right away, but once i login i go into a "Redirect Loop" error from chrome, ive tried diferent stuff and the problem seams that i never end up with a $session. the code below is the only thing that i have currently its login.php page.

<?php
session_start();
// added in v4.0.0
require_once "facebook-php-sdk-v4-4.0-dev/autoload.php";
//require 'functions.php';  
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication('APPID','APPSCRET');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://fbtwitsergio.byethost12.com/login.php' );
try {
    $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
    // When Facebook returns an error
} catch( Exception $ex ) {
    // When validation fail ———got a echo from here
}
// see if we have a session
if ( isset( $session ) ) {
    header("Location: index.php");
} else {
    $loginUrl = $helper->getLoginUrl();
    header("Location: ".$loginUrl);
}
?>

已经发现出了问题。。。服务器很可能已关闭端口,因此无法连接到FB SDK。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM