0

I want that a User gets redirected after the login, I've read all of the potential doublicates, nothing there fixes it (e.g. using next instead of redirect_uri).

My Code:

    <?php
session_start();
// added in v4.0.0
require_once 'autoload.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','APPSECRET' );

// login helper with redirect_uri
    $helper = new FacebookRedirectLoginHelper('http://localhost/fbconfig.php/' );
try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

// see if we have a session
if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();

  // get response
  $graphObject = $response->getGraphObject();
        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
        $femail = $graphObject->getProperty('email');    // To Get Facebook email ID
    /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $femail;
    /* ---- header location after session ----*/
  header("Location: login.php");
} else {
  $loginUrl = $helper->getLoginUrl();
    header("Location: ".$loginUrl);
    exit();
}
?>

As mentioned, Chrome gives an error that there are too many redirects.

ffritz
  • 2,180
  • 1
  • 28
  • 64
  • remove `'next' => 'http://localhost/index.php',` it has nothing to do with redirection according to your code – urfusion Apr 22 '16 at 11:22
  • @urfusion: Then Chrome says "Facebook has to many redirects". – ffritz Apr 22 '16 at 11:24
  • try with removing `'next' => 'http://localhost/index.php'`, and place `exit()` after `header` – urfusion Apr 22 '16 at 11:26
  • Same problem, it doesn't redirect properly. It does log me in though, when I go back manually, everything is fine. Just the redirect after the login doesn't work. – ffritz Apr 22 '16 at 11:29
  • still you are getting same issue? if yes, then place full code. – urfusion Apr 22 '16 at 11:30
  • Update the code above in the Question. – ffritz Apr 22 '16 at 11:32
  • check http://stackoverflow.com/questions/13065649/php-sdk-too-many-redirects – urfusion Apr 22 '16 at 11:36
  • The Solution there was that the secret was wrong, not the case here. It logs me in successfully, but I have a look at the common redirection problem from the SDK. Thanks! – ffritz Apr 22 '16 at 11:39
  • Change `http://localhost/fbconfig.php/` with a actual url. Localhost is not a real url. Either create a `virtual host` or go live – urfusion Apr 22 '16 at 11:41

0 Answers0