[SOLVED] facebook php-sdk not logging out

Issue

I’m having a hard time getting this to work. I use the following to generate the logout url:

$logout = "https://www.facebook.com/logout.php?next=" . urlencode('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']) . "&access_token=" . $facebook->getAccessToken();

Which generates the correct (worked with the last version) url:

https://www.facebook.com/logout.php?next=http%3A%2F%2F...&access_token=AA....ZD

However this does not actually log the user out. I tried using

$facebook->getLogoutUrl(array('next' => 'myurl')) 

which generates pretty much the same url. This also did not work. I am lost as to why its not logging the user out. I actually tried manually putting the address into the address bar but it redirects me to the Facebook homepage.

Solution

If you request the offline_access permission when using the Facebook PHP SDK (and sometimes even without it), it makes the default logout functionality not work very well. To fix this, following worked for me:

//change your logout url to 
$logoutUrl = $facebook->getLogoutUrl(array( 'next' => ($fbconfig['baseurl'].'logout.php') ));

//on logout page
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'domain.com');
session_destroy();
header('Location: /');

Answered By – Sudhir Bastakoti

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.