2012-03-20 161 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主頁。