douzhan1868 2014-02-21 05:10
浏览 156

facebook注销只从网站注销而不是从facebook?

I am doing the facebook login and logout from a website. So if a user wants to login into the site he will click on facebook login and when he will click on logout then he will automatically logout from both facebook and from the site as well. So all for that I have made my code like this In index.html my code is like this

<div id="fb-root"></div>
<script type="text/javascript">
//<![CDATA[
window.fbAsyncInit = function() {
   FB.init({
     appId      : 'XXXXXXXXXXXXX', // App ID
     channelURL : '', // Channel File, not required so leave empty
     status     : true, // check login status
     cookie     : true, // enable cookies to allow the server to access the session
     oauth      : true, // enable OAuth 2.0
     xfbml      : false  // parse XFBML
   });
};
// logs the user in the application and facebook
function login(){
FB.getLoginStatus(function(r){
     if(r.status === 'connected'){
            window.location.href = 'fbconnect.php';
     }else{
        FB.login(function(response) {
                if(response.authResponse) {
              //if (response.perms)
                    window.location.href = 'fbconnect.php';
            } else {
              // user is not logged in
            }
     },{scope:'email'}); // which data to access from user profile
 }
});
}

// Load the SDK Asynchronously
(function() {
   var e = document.createElement('script'); e.async = true;
   e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';                
   document.getElementById('fb-root').appendChild(e);
}());

//]]>
</script>
<a href='#' onclick='login();'>Facebook Login</a>

and in fbconnect.php my code is like this

<?php
    require 'src/facebook.php';
    $facebook = new Facebook(array(
           'appId'  => 'XXXXXXXXXXXXXXXXX',
           'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
           'cookie' => true,
    ));
    $user = $facebook->getUser();
    $loginUrl = $facebook->getLoginUrl();
    //echo "<a href='$loginUrl'>login</a>";

    $logoutUrl = $facebook->getLogoutUrl();
    //echo $loginUrl; 
    if($user){
        $_SESSION['user_info'] = $user; 
        $_SESSION['user_pro']= $facebook->api('/me');
        echo $_SESSION['user_pro']['first_name'];
        echo $_SESSION['user_pro']['last_name'];
        echo '<pre>';
        //print_r($_SESSION);
        echo '</pre>';
    }
    else{
        echo 'not logged in '; 
    }
    echo "<a href='logout.php'>log out </a>"
?>

and in logout.php my code looks like this

<?php
require 'src/facebook.php';    //including the facebook php sdk
$facebook = new Facebook();
$token = $facebook->getAccessToken();
$url = 'index.html';
$facebook->destroySession();
session_destroy();
header('Location: '.$url);
?>

All this is doing the site logout but it is not doing the logout from facebook. So can someone kindly tell me how to do logout from both facebook and website at a same time? Any help and suggestions will be reallly appreciale. Thanks

  • 写回答

2条回答 默认 最新

  • douju2599 2014-02-21 05:15
    关注

    Dont'use any redirect <a href='logout.php'>log out </a>

    only need on action facebook session destroy

    if(isset($_GET['action']) && $_GET['action'] === 'logout'){
            $facebook->destroySession();
        }
    

    Then after you can use your site session destroy For more info :- PHP SDK - Facebook Logout

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧