I have been using this code for facebook sdk logout but its not working. However i can login iwth it successfully. Here is the code.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
}
else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_about_me, user_hometown')
);
}
?>
<?php if ($user){ ?>
<a href="<?php echo $logoutUrl; ?>">Logout Here</a>
<?php }else{ ?>
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php }?>
The default Facebook SDK uses php's built in session implementation to store it's data. Among these the last logged in user id.
When your user clicks on the logout link, facebook will log her out, and send her back to your site, however facebook can't delete the values in your site's $_SESSION
. Add a next
parameter to the $facebook->getLogoutUrl()
so facebook will send the user back there, and you can clear the whole session (after all the user has logged out) with session_destroy.
If you don't want to clear the whole session just the facebook specific values, there's a method for that called destroySession on the BaseFacebook
class (for some reason not listed in offical sdk docs).