[Solved] Facebook logout button and redirect after logout

I use this code

<fb:login-button autologoutlink="true" perms="user_likes" size="large"></fb:login-button>

to create a login/logout fb button.
Everything works, after the login, the login button become a logout button. But If the user click on the logout button, the current page is not refreshed and so all the things that should appear only when the user is authenticated are still there until a manual page refresh is done.

This doesn’t happen if I get the logout url (Javascript SDK)

$logoutUrl = $facebook->getLogoutUrl();

and then implement a logout button myself; in that case a proper “next” parameter (with the url of the current page) is passed and the current page is reloaded.

I still would like to use the first solution, is it possible to make it use the “next” parameter?

Enquirer: Eugenio


Solution #1:

Do the redirect yourself – add this to JavaScript, somewhere after FB.init():

  FB.Event.subscribe("auth.logout", function() {window.location = '/logout'});

This function will fire when logout through the FB button happens.

Solution #2:

For integrated authentication (Facebook + Asp.Net MVC), I just use Javascript and FormsAuthentication.SignOut();

function LogoutFacebook() {    
FB.logout(function (response) {
    window.location = "/facebook/logout/";
});   }
Respondent: Fernando JS

Solution #3:

Above answer by Piskvor did it for me. Its crazy how many hours I’ve spend trying to figure this out.

Main problem with plugins such as this Facebook for CakePHP is that they don’t come with updates. APIs, especially popular ones like Facebook, change all the time because they are being imporved. If the guy who wrote it initially as a hobby moves on with his life and stops updating the SDK people who are less knowladgable on how to alter these things become stuck.


Nevertheless, thanks for a great solution Piskvor, here is my piece of code for


            $init .= $this->Html->scriptBlock(

window.fbAsyncInit = function() {
        appId : '{$appId}',
        session : {$session}, // don't refetch the session when PHP already has it
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml : true // parse XFBML
     FB.Event.subscribe("auth.logout", function() {
       window.location = '/users/logout'

The key piece of code here is:

     FB.Event.subscribe("auth.logout", function() {
         window.location = '/users/logout'
Respondent: user1052933

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy