0
votes

I am using facebook's PHP SDK to log user into my website. Now when I click on logout button, it successfully clears the session. When he again clicks on login with facebook button, he automatically logs into my website with the same facebook account he used before logging out instead of showing logging in page.

<?php
    session_start();  
    /*
        echo "before logout.</BR></BR>"; 
        echo 'id: ' . $_SESSION['id']."</BR></BR>";
    */

    require_once 'Facebook/autoload.php';
    require_once 'Facebook/Facebook.php';

    $config = array();
    $config['appId'] = 'My Appid';
    $config['secret'] = 'My Secret';
    $config['fileUpload'] = false;

   $fb = new Facebook\Facebook([
        'app_id' => 'My Appid', // Replace {app-id} with your app id
        'app_secret' => 'My Secret',
        'default_graph_version' => 'v3.2',
    ]);

    //$facebook = new Facebook($config);
    //$token = $fb->getAccessToken();

    //$accessToken = $fb->getAccessToken(); // Not working - Error showing - undefined method

    //echo $_SESSION['fb_access_token']; - This contains some long access token

    unset($_SESSION['id']);
    //echo $accessToken;
    /*
        echo "after logout.</BR></BR>"; 
        echo 'id : '. $_SESSION['id']."</BR></BR>";
    */
    //$url = 'https://www.facebook.com/logout.php?next=https://rocketevent.in&access_token='.$_SESSION['fb_access_token']; - going to facebook page, not returning back 
    //echo $url;
    session_destroy();
    $fb->getLogoutUrl();
    //header('Location: '.$url);
   //header("Location: ../../index.php");
?>
1
If the user was logged into Facebook already before they logged in to your app, then this is the expected behavior, and nothing you can do anything about AFAIK. Only if the user logged in to Facebook in the process of logging in to your app, then calling this logout URL is supposed to log them out of your app and Facebook. - misorude
The user is only allowed to have one account. So does it matter? - WizKid

1 Answers

0
votes

You should provide your 'app_id' and 'app_secret'. You can get these from https://developers.facebook.com