Facebook login not redirecting [closed]

2019-05-18 21:26发布

Why is the following not working?

// Login or logout url will be needed depending on current user state.
if ($user) {

    $logoutUrl = $facebook->getLogoutUrl();

} else {

    $loginUrl = $facebook->getLoginUrl();
    header("Location: ".$login_url);

}

Using xdebug, I can see that it is going through the else section, but when it gets to the end of the file, it stays on the current page, instead of opening the new login_url page which should show the facebook login screen.

Anyone know why it's not going to the facebook page?

3条回答
Root(大扎)
2楼-- · 2019-05-18 21:55

Figured out the problem. I had a typo... I was assigning the url to $logoutUrl and was trying to get the url from $logout_url...

Thanks

查看更多
Animai°情兽
3楼-- · 2019-05-18 21:56

Try this:

$facebook = new Facebook(array(
  'appId'  => '', // app id
  'secret' => '', // the secret
));

// Get User ID
$user = $facebook->getUser();

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
  header("Location: ".$login_url); // the user is not logged in, redirect him to the login page
  exit();
}
查看更多
萌系小妹纸
4楼-- · 2019-05-18 22:09

I used this solution in php:

$loginUrl = $facebook->getLoginUrl(array(
            'scope' => $scope,
            'redirect_uri' => $app_url,
            ));


            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
查看更多
登录 后发表回答