[SOLVED] facebook php-sdk not logging out


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:


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.


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');
header('Location: /');

Answered By – Sudhir Bastakoti

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.