Facebook PHP SDK - will not logout properly

前端 未结 8 751
滥情空心
滥情空心 2021-02-09 17:21

I\'ve been searching for hours for the solution to this problem but can\'t find one that works for me. When i click \"Logout\" on my site the user information is still visible a

8条回答
  •  醉梦人生
    2021-02-09 17:30

    Because I still have PHP 5.3 at my CentOS 6.7 server in year 2016 and don't want to take the hassle of upgrading the PHP version - I still use the old facebookarchive/facebook-php-sdk instead of the newer facebook/facebook-php-sdk-v4 library.

    And here is how I handle the logout in my app:

     REPLACE_ME,
            'secret' => REPLACE_ME,
    ));
    
    if (isset($_REQUEST['logout'])) {
            $client->destroySession();
            header('Location: ' . REDIRECT);
            exit(0);
    }
    
    if ($client->getUser()) {
            try {
                    $me = $client->api('/me?fields=id,first_name,gender');
                    $body = '
    ' . print_r($me, TRUE) . '
    '; } catch (FacebookApiException $ex) { error_log($ex); $body = '
    ' . htmlspecialchars($e->getMessage()) . '
    '; } } else { $body = sprintf('

    Login

    ', $client->getLoginUrl()); } ?> <?= TITLE ?>

    Logout

    Do not forget to -

    1. Get web client id and secret at Facebook console
    2. Authorize the https://example.com/myapp/ at the same place

提交回复
热议问题