2012-03-20 146 views
0

我已经下载了最新版本的facebook php sdk。我可以在我的网站上使用fb登录。但注销不起作用。脚本会记住用户数据。如何纠正这个问题?以下是我正在使用的代码。facebook注销不起作用

<?php 
require '../src/facebook.php'; 

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

// Get User ID 
$user = $facebook->getUser(); 

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 ($user) { 
$logoutUrl = $facebook->getLogoutUrl(); 
} else { 
$loginUrl = $facebook->getLoginUrl(); 
} 


?> 
<!doctype html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
<title>php-sdk</title> 
<style> 
    body { 
    font-family: 'Lucida Grande', Verdana, Arial, sans-serif; 
    } 
    h1 a { 
    text-decoration: none; 
    color: #3b5998; 
    } 
    h1 a:hover { 
    text-decoration: underline; 
    } 
</style> 
</head> 
<body> 
<h1>php-sdk</h1> 

<?php if ($user): ?> 
    <a href="<?php echo $logoutUrl; ?>">Logout</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 ?> 

<h3>PHP Session</h3> 
<pre><?php print_r($_SESSION); ?></pre> 

<?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 ?> 


</body> 
</html> 

回答

0

从您的Facebook帐户中删除应用程序,然后重试。 这解决了我的问题。

0
  1. 加上array( '下一步'),以$logoutUrl
  2. 使用session_destroy();

    $logoutUrl = $facebook->getLogoutUrl(array('next' => 'url_you_are_redirecting_user_to')); session_destroy();

采取的通知,即重定向链接应该是在同一个域范围内的所有Facebook应用程序。否则,您将被重定向到Facebook主页。