dqqn32019 2013-04-15 22:17
浏览 19
已采纳

使用getLogoutUrl()时无法在我的网站上注销

I've got 2 tabs open in Firefox, one is my website and the other is Facebook. Without the app authorised I get a login link, I click this which I am then prompted to auth the app which I do so.

I've now got on screen the logout URL provided by getLogoutUrl() - when I click this it redirects back to my site which I am happy with however it is still classing me as logged in. If I refresh the other tab with Facebook on I am now logged out. It seems there's some hangover on the session??

<?php
require_once("fb/facebook.php");

$config = array();
$config['appId'] = '...';
$config['secret'] = '...';
$config['fileUpload'] = false; // optional

$facebook = new Facebook($config);
$user_id = $facebook->getUser();

if($user_id) {
    //Got an ID - Facebook says we're logged in
    try {

        $user_profile = $facebook->api('/me','GET');
        echo "<img src=\"http://graph.facebook.com/".$user_profile['username']."/picture\"><a href=\"".$user_profile['link']."\">" . $user_profile['name']."</a>";
        $logout_url = $facebook->getLogoutUrl();
        echo "<a href=\"" . $logout_url . "\">Logout</a><br><br><br>";

    } 
    catch(FacebookApiException $e) {
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
    }   
} 
else {
    // Not logged in - give URL to login
    $login_url = $facebook->getLoginUrl();
    echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
  • 写回答

1条回答 默认 最新

  • duanli6834 2013-10-08 15:11
    关注

    You need to destroy the session.

    $config = array();
    $config['appId'] = 'xxxx';
    $config['secret'] = 'xxxxx';
    
    $facebook = new Facebook($config);
    
    if(isset($_GET['act']) && $_GET['act'] == "logout") {
        $facebook->destroySession();
    }
    
    
    $user = $facebook->getUser();
    echo $user;
    if ($user) {
    
        try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
        } catch (FacebookApiException $e) {
        echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
        $user = null;
        }
        echo "<pre>";
        print_r($user_profile);
        echo "</pre>";  
        $logout = $facebook->getLogoutUrl();
    
        //echo $logout;
    
        echo "<a href='test.php?act=logout'>Logout</a>";
    
    
    } else {
    
        $login = $facebook->getLoginUrl(array("scope"=>"email","display"=>"popup","redirect_uri"=>"http://domain.com/test.php"));
    
        echo "<a href='".$login."'>Login</a>";
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line