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, here’s what worked for me:
- Change your logout url:
$logoutUrl = $facebook->getLogoutUrl(array( 'next' => ($fbconfig['baseurl'].'logout.php') ));
- On your logout.php page, add the following code:
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'domain.com'); session_destroy(); header('Location: /');
This should correctly logout your users.
Thanks!… It work’s nice!…
i want that user must go through fb login everytime….but above solution not work fine for me!.
Any idea what should I do?
Check your login link, it may be setting a cookie.
hi, you didn’t tell that we had to include the facebook js to the logout.php page! It wouldn’t work for me until I included it.
eg
require ‘scripts/facebook.php’;
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
‘appId’ => ‘xxxxxxxxxxxxxx’,
‘secret’ => ‘xxxxxxxxxxxxxxxxxxxxxxxxx’,
));
setcookie(‘fbs_’.$facebook->getAppId(), ”, time()-100, ‘/’, ‘http://www.repjesus.com‘);
session_destroy();
header(‘Location: /’);
THANK YOU! I was going nuts.
You are a star! Bejesus that was right pain!
Thank you very much!!!!You just save my life today. I was getting lots of errors and then I found this. Problem solved.
Thanks again!!!!
wow i was stuck with logout problem for hours and you just fixed it. Thanks a million times! ;P