Facebook PHP SDK - will not logout properly

前端 未结 8 757
滥情空心
滥情空心 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:37

    Here is how I logout using the latest PHP-SDK:

    login.php

    require_once("php-sdk/facebook.php");
    
    // Create our Application instance (replace this with your appId and secret).
    $facebook = new Facebook(array(
      'appId'  => 'xxx',
      'secret' => 'xxx',
    ));
    
    // Get User ID
    $user = $facebook->getUser();
    
    // We may or may not have this data based on whether the user is logged in.
    //
    // If we have a $user id here, it means we know the user is logged into
    // Facebook, but we don't know if the access token is valid. An access
    // token is invalid if the user logged out of Facebook.
    
    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }
    
    // Login or logout url will be needed depending on current user state.
    if ($user) {
        $logout_params = array('next'=>'http://www.pittsburghpartycentral.com/logout.php');
      $logoutUrl = $facebook->getLogoutUrl($logout_params);
    } else {
        $login_params = array(
                            'scope' => 'email',
                            'display' => 'popup'
                            );
      $loginUrl = $facebook->getLoginUrl($login_params);
    }
    
    // This call will always work since we are fetching public data.
    $naitik = $facebook->api('/naitik');
    
    ?>
    
    
      
        php-sdk
        
      
      
        

    php-sdk

    Logout ()
    Login using OAuth 2.0 handled by the PHP SDK: Login with Facebook

    PHP Session

    You

    Your User Object (/me)

    You are not Connected.

    Public profile of Naitik

    logout.php

    
    
    
    
    
    Log Out
    
    
    
    

    You have successfully logged out!

    Return to the connect page

提交回复
热议问题