简体   繁体   中英

Facebook getLogoutUrl() doesn't work as expected

This is my code :

    <?php
require_once("facebook-php-sdk/src/facebook.php");
    define('YOUR_APP_ID', 'xxxxxxxxxxxxx');
    define('YOUR_APP_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxx');
    $facebook = new Facebook(array(
     'appId' => YOUR_APP_ID,
     'secret' => YOUR_APP_SECRET,
    ));
    $userId = $facebook->getUser();
    if($userId){
         $userInfo = $facebook->api('/' + $userId);
         $fbid = $userInfo['id'];
         $params = array();
         echo '<a href='.$facebook->getLogoutUrl($params).'><div class="text-facebook"><img style="vertical-align:middle;" src="/img/fbicon.png">Logout</div></a>';                         
               }
                else{
                  $permission = array('scope' => 'email');
                  echo '<a href='.$facebook->getLoginUrl($permission).'><div class="text-facebook"><img style="vertical-align:middle;" src="/img/fbicon.png">Login with Facebook</div></a>';
                     }
?>

Login works perfectly, but when I click the Logout button it logs me out of facebook.com, but it stays logged on my website, which is exactly the opposite of what I want. I want the link to delete all facebook information from my website, but keep the user logged to facebook.

I don't know if I explained correctly what I need, but I'll clear things up if someone asks.

If you want the user to log out from your site but stay logged in to facebook then the answer is simple:

Don't use facebook->getlogouturl()

If after a successful login, you set a variable to be true, and use that to permit actions you only grant to a logged in user, then all your logout button will need to do is set that variable to false.

The issue here isn't the logout link (which is working properly, since it logs you out of Facebook), but it is how your website checks whether you are still logged into Facebook

The Facebook API you are using only deals with Facebook's side of things. The login link will log you into Facebook, and the logout link will log you out of Facebook. It doesn't affect your website directly.

You'll need to find out how your website decides whether you are still logged into Facebook or not, and go from there.

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