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 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题