2

I am using the latest version of PHP SDK for Facebook (3.2.1)

I was wondering, when logging out using the function provided in base_facebook.php from the sdk, if there was a way to stop it from actually logging out of facebook, but still deleting the session for the website application?

Below is the logout function from base_facebook.php

/**
* Get a Logout URL suitable for use with redirects.
*
* The parameters:
* - next: the url to go to after a successful logout
*
* @param array $params Provide custom parameters
* @return string The URL for the logout flow
*/

 public function getLogoutUrl($params=array()) {
 session_destroy();
 return $this->getUrl(
  'www',
  'logout.php',
 array_merge(array(
  'next' => $this->getCurrentUrl(),
  'access_token' => $this->getUserAccessToken(),
  ), $params)
 );
}

and then my logout url is: $logoutUrl = $facebook->getLogoutUrl();then obviously using a anchor tag to logout: <a href="<?php echo $logoutUrl; ?>">Logout</a>

Thank you.

4

2 回答 2

6

不要使用 $logoutUrl。

 <li><a href="?action=logout">Logout</a></li>

并在你的 php 代码中添加这个。这只会将您从您的应用程序中注销。

if(isset($_GET['action']) && $_GET['action'] === 'logout'){
        $facebook->destroySession();
    }
于 2013-07-30T10:08:13.027 回答
2

创建一个文件 logout.php

<?php 
session_start();            //start session
$_SESSION = array();    //clear session array
session_destroy();      //destroy session
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Log Out</title>
</head>

<body>
<p>You have successfully logged out!</p>
<p>Return to the <a href="....index.php">Home</a> page</p>

</body>
</html>

并更改您检查用户状态的代码

if ($user) { 
    $params = array( 'next' => 'http://....../logout.php' );
    $logoutUrl = $facebook->getLogoutUrl($params);
} else {
  $loginUrl = $facebook->getLoginUrl();
}

使用 $logoutUrl 注销用户。

<?php if ($user): ?>
<?php echo "Welcome, ".$me['first_name']. " " .$me['last_name']   ." <br />";
      echo "Id: " . $me['id'] ." <br />";  ?>

<a href="<?php echo $logoutUrl; ?>">  Logout </a> <br />

<?php else: ?>
  <a href="<?php echo $loginUrl; ?>"> 

   <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif"> </a>  
 <?php endif ?>

希望它能正常工作

于 2014-04-10T10:27:39.037 回答