Facebook PHP SDK-无法正确注销 [英] Facebook PHP SDK - will not logout properly

查看:60
本文介绍了Facebook PHP SDK-无法正确注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找解决这个问题的方法,但找不到适合我的方法.当我在我的站点上单击注销"时,用户信息仍然可见,并且注销按钮仍然显示.这是代码:

I've been searching for hours for the solution to this problem but can't find one that works for me. When i click "Logout" on my site the user information is still visible and the logout button is still displayed. Here is the code:

require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'xxxx',
  'secret' => 'xxxx',
));

// Get User ID
$user = $facebook->getUser();
var_dump($user);
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.

if ($_GET['logout'] == "yes") {
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'http://gno.....ment/index.php');
session_destroy();
header("Location: ".$_SERVER['PHP_SELF']."");
}

if ($user_profile) {
  $logoutUrl = $facebook->getLogoutUrl;
} else {
  $loginUrl = $facebook->getLoginUrl(array('scope' => 'email,publish_stream,user_status',
  'canvas' => 1,
  'fbconnect' => 0,
  'redirect_uri' => 'http://gno.....ment/index.php'));
}

... .....

..... .....

<?php if ($user): ?>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">

<h3>Your User Object (/me)</h3>
<pre><?php print_r($user_profile); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>

<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout of FB</a>
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>

似乎if ($_GET['logout'] == "yes")可能是我的答案,但我无法使其正常运行.我不知道logout是从哪里获得的或在哪里定义的?

It seems that if ($_GET['logout'] == "yes") might be the answer for me but i can't get it working. I don't know where logout is gotten from or where it is defined?

这似乎是一个常见问题,但我无法弄清楚.非常感谢您的帮助.

This seems to be a common issue but i can't figure it out. I'd really appreciate some help.

推荐答案

使用PHP SDK确实很容易,文档非常糟糕.您无需重定向到Facebook.您只需要清除Facebook类设置的会话,Facebook基类中就有一个名为 destroySession()的函数.在这里,我正在努力.

Doing it with PHP SDK is really easy, the documentation is just really awfull. You do not need to redirect to Facebook. You just have to clear the session that the Facebook class sets, there is a function for that in the Facebook base class called destroySession(). Here I'm doing it on a get.

require_once('libs/facebook.php');

$facebook = new Facebook(array(
    'appId'  => '1121111110112',
    'secret' => 'bcfsaasaaaaaa2b7adsae3a4dd5'
)); 

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

$ facebook-> getLogoutUrl()将用户注销Facebook.

The $facebook->getLogoutUrl() logs the user out of Facebook.

这篇关于Facebook PHP SDK-无法正确注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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