简体   繁体   中英

Facebook getLoginUrl() not redirected to specified page

When a user attempts to login to my website using their facebook account, I am trying to redirect to a script that checks the users id against my db to see if they have registered. When I click login it brings up a facebook page to login using fb credentials but then just redirects to the home page of mywebsite rather than running the script that checks the user against the database.

This is the code on my home page where I attempt to login.

<?php
require '.../src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'APP_ID',
  'secret' => 'SECRET',
  'cookie' => true,
));

//2. retrieving session
$session = $facebook->getUser();

//3. requesting 'me' to API
$me = null;
if ($session) {
    try {
       $uid = $facebook->getUser();
       $me = $facebook->api('/me');
    } catch (FacebookApiException $e) {
       error_log($e);
    }
}

//4. login or logout
if ($me) {
    $logoutUrl = $facebook->getLogoutUrl(array(
        'next'=>'http://.../logout.php'
    ));
} else {
    $loginUrl = $facebook->getLoginUrl(array(
       'next'=>'http://.../checkFBLogin.php'
    ));
}

?>

Futher down:

<?php if ($me): ?>
    <a href="<?php echo $logoutUrl; ?>">Logout with Facebook</a>
<?php else: ?>
    <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php endif ?>

It would also be helpful to know if there is a way to check against my database before logging into Facebook to check if they are registered to my website.

The name of the key in the array is not next its redirect_url.

$loginUrl = $facebook->getLoginUrl(array(
       'redirect_url'=>'http://.../checkFBLogin.php'
    ));

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