$ facebook-> getUser()ALWAYS返回ID - 无法注销 [英] $facebook->getUser() ALWAYS Returning ID - Can't Logout

查看:233
本文介绍了$ facebook-> getUser()ALWAYS返回ID - 无法注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,无论我做什么,这总是返回有效的ID和Facebook信息。要注销,我正在使用Facebook.Logout,重定向到我清除所有Cookie(包括fbsr_)的页面。我甚至手动注销Facebook,它仍然返回有效的ID!这是一个Facebook Connect应用程序。这是我的应用程序代码,

  $ uid = $ facebook-> getUser(); 

if($ uid){
try {
$ me = $ facebook-> api('/'+ $ uid);
} catch(FacebookApiException $ e){
echo $ e;
error_log($ e);
$ uid = NULL;
}
}

然后我的PHP注销代码

  $ app_id =XXXX; 
session_name('QEW');
session_start();
session_regenerate_id(true);
session_unset();
session_destroy();
$ facebook-> destroySession();
if(isset($ _ COOKIE ['fbsr_'。$ app_id])
{
setcookie('fbsr_'。$ app_id,$ _COOKIE ['fbsr_'。$ app_id] () - 3600,/);
setcookie('PHPSESSID',$ _COOKIE ['PHPSESSID'],time() - 3600,/);

unset($ _ COOKIE ['fbsr_'。$ app_id]);
unset($ _ COOKIE ['PHPSESSID']);
}

编辑
我的Javascript代码,

  window.fbAsyncInit = function(){
FB.init({
appId:'XXX' ,cookie:true,
status:true,xfbml:true,oauth:true,
channelURL:'~~ .com / channel.html'
});
};
(function(){
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +'// connect。
e.async = true;
document.getElementById('fb-root')。appendChild(e);
}());
函数登录(io)
{
FB.getLoginStatus(function(response)
{
if(response.status =='connected')
{
if(io == 1)
{
FB.login(function(response)
{
if(response.authResponse)
{
cU(response.authResponse.userID);
}
},{scope:'email'});
}
else
{
FB.logout(function(response){});
window.location =./ logout.php;
}
}
else
{
FB.login(function(response)
{
if(response.authResponse)
{
cU(response.authResponse.userID);
}
},{scope:'email'});
}
});
}

然后在注销之后,我转到另一个调用第一个再次阻止代码,并且它只是重新填充cookies,因为它获得了有效的用户标识。我该怎么解决这个问题?谢谢

解决方案

您通过php删除cookie。之后,下一个请求JS API恢复它。



从Facebook的注销唯一有效的方法是将用户重定向到注销url: / p>

  echo $ facebook-> getLogoutUrl(); 

或从客户端JS API FB.logout();


for some reason no matter what I do, this is always returning a valid ID and Facebook information. To logout, I am using Facebook.Logout, redirecting to a page where I clear ALL cookies including "fbsr_" ones. I even logged out of Facebook manually and it is still returning a valid ID! This is for a Facebook Connect application. Here is my app code,

$uid = $facebook->getUser();

if ($uid) {
  try {
    $me = $facebook->api('/'+$uid);
  } catch (FacebookApiException $e) {
      echo $e;
    error_log($e);
    $uid = NULL;
  }
}

Then my PHP logout code,

$app_id="XXXX";
session_name('QEW');
session_start();
session_regenerate_id(true);
session_unset();
session_destroy();
$facebook->destroySession();
if (isset($_COOKIE['fbsr_' . $app_id])) 
{
      setcookie('fbsr_' . $app_id, $_COOKIE['fbsr_' . $app_id], time() - 3600, "/");
      setcookie('PHPSESSID', $_COOKIE['PHPSESSID'], time() - 3600, "/");

      unset($_COOKIE['fbsr_' . $app_id]);   
      unset($_COOKIE['PHPSESSID']);
}

EDIT My Javascript code,

window.fbAsyncInit = function() {
    FB.init({ 
        appId:'XXX', cookie:true, 
        status:true, xfbml:true, oauth:true,
        channelURL:'~~.com/channel.html'
        });
};
(function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
          }());
function login(io)
{
    FB.getLoginStatus(function(response)
    {
        if(response.status == 'connected')
        {
            if(io==1)
            {
                FB.login(function(response) 
                {
                  if (response.authResponse) 
                  {
                     cU(response.authResponse.userID);
                  }
                },{scope:'email'});
            }
            else
            {
                FB.logout(function(response){});
                window.location="./logout.php";
            }
        }
        else
        {
            FB.login(function(response) 
            {
              if (response.authResponse) 
              {
                 cU(response.authResponse.userID);
              }
            },{scope:'email'});
        }
    });
}

Then after "logging out", I go to another page that calls the first block of code again, and it just repopulates the cookies because it gets a valid user id back. how can I fix this? Thanks

解决方案

You delete cookie by php. After that on next request JS API restores it.

The only and valid way to logout from facebook is to redirect user to logout url:

echo $facebook->getLogoutUrl();

or the same from the client JS API FB.logout();

这篇关于$ facebook-> getUser()ALWAYS返回ID - 无法注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆