30 responses to “Fixing Facebook’s PHP SDK logout”

  1. Sandip Ghosh

    Thanks!… It work’s nice!…

  2. pushkar rana

    i want that user must go through fb login everytime….but above solution not work fine for me!.
    Any idea what should I do?

  3. Jay

    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: /’);

  4. Carl-Fredrik Herö

    THANK YOU! I was going nuts.

  5. Ben Baker

    You are a star! Bejesus that was right pain!

  6. Indira Chavez

    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!!!!

  7. Francis

    wow i was stuck with logout problem for hours and you just fixed it. Thanks a million times! ;P

  8. sridevi

    SAM Thank you Very Much….

  9. phpdog
  10. rob

    Fixed it, finally! THANKS!

  11. dpasqua

    Thanks, It helped me a lot.

  12. Attila

    Hi,
    It is quite strange. I tried to logout user with official method: $facebook->getLogoutUrl(); It creates a link which looks good (https, token, etc.). It redirects to facebook logout.php than back to my page but the session remains same: FB.getLoginStatus: connected.
    Now with your solution I can’t create the Cookie. I can create other Cookies e.g.: setcookie(“TestCookie”, ‘blah blah’); but after the redirection your Cookie not exists in the Console. :(
    Do you have any idea?

  13. ashish kumar gupta

    Thank you very much.
    this code solved my problem……………..

  14. Sushant

    Thank you. I was stuck for an hr finding solution to logout. Even the fb docs dont have a good explanation.

  15. Wallace

    what it’s a baseurl ?
    i don’t have in my facebook config.

  16. Ashish

    In codeigniter, I have fixed it.
    The cookie name is PHPSESSID

    http://ashish-thakur.blogspot.in/2012/07/facebook-php-sdk-logout-resolved.html

  17. Lalit Kumar

    Thanks a lot, It works :-)

  18. pavanpareek

    thinks….

  19. shanmao

    Thank you very much!!!!

  20. prasetyawan

    Thanks Bro.. it works great :)

  21. Joko Widodo (Jokowi)

    Thanks Dude, it works like a charm,

  22. Arti Goyal

    Very nice tutorial..Thanks

  23. Michael

    Thank you so much!

  24. Siddharth Das

    THANK YOU SO MUCH !!! I have no idea how it works ..but it works !!

  25. Amit

    Thank you very much SAM

  26. aung ko

    Can you please prefer for $fbconfig?

  27. Jon

    My goodness. I’ve been losing my mind in frustration for over an hour. Thank you so much for this post!

  28. vijetha

    thanks a lot

Leave a Reply