简体   繁体   English

用户注销Facebook时注销网站

[英]Log Out of Website when User Logs Out of Facebook

I am using the Facebook Connect PHP SDK to allow users to log into my website: 我正在使用Facebook Connect PHP SDK允许用户登录我的网站:

try {
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));
} catch(Exception $o) {
    print_r($o);    
}

// Facebook Authentication part
$user       = $facebook->getUser();    
$loginUrl   = $facebook->getLoginUrl(
                array(
                    'scope'         => 'email,user_likes,publish_actions,read_stream,friends_likes,user_checkins,user_location,friends_checkins,user_status',
                    'redirect_uri'  => $fbconfig['baseurl'].'load-data.php',
                    'cancel_url'    => $fbconfig['baseurl'].'/index.php'
                )
            );

The login URL is created, and the user is logged into the site successfully. 创建登录URL,并且用户成功登录到站点。 The problem is that when the user logs out of Facebook in another tab, I want to get this status and log the user out from my program using the Facebook SDK. 问题是,当用户在另一个选项卡中注销Facebook时,我想获得此状态并使用Facebook SDK从程序中注销用户。

How can I log the user out when they log out of Facebook? 用户注销Facebook时如何注销?

Thanks for reading my question. 感谢您阅读我的问题。

I don't think you can find out when the user logged out from Facebook without messing up with the FB Session directly as this is different from your app Session. 我认为您无法找到用户何时从Facebook注销而不直接弄乱FB Session,因为这与您的应用Session不同。 And I don't thing this would be a good think to do. 而且我认为这不是一个好主意。

A different approach would be to logout the user from your app but I don't know if it would solve your problem. 一种不同的方法是从您的应用程序注销用户,但我不知道这是否可以解决您的问题。

        <script type="text/javascript">

        var int=self.setInterval(function(){checkSession()},1000);

        function checkSession() {
             var request = false;
                if(window.XMLHttpRequest) { // Mozilla/Safari
                    request = new XMLHttpRequest();
                } else if(window.ActiveXObject) { // IE
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                }

                request.open('get', 'checksession.php', true);
                request.send();
                request.onreadystatechange = function() {

                    if(request.readyState == 4) 
                    {
                        var session = request.responseText;
                         if(session=="false")  {
                            alert("Your Session has expired");
                            window.location = "login.php";
                         }
                    }
                }
                request.send(null);
            }

            </script>

php script PHP脚本

    $user = $facebook->getUser();

    if ($user) {
      echo "false";
    } else {
      echo "true";
    }

Can't logout using Facebook API 无法使用Facebook API注销

I think this maybe helpful. 我认为这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM