title: How to properly log out of facebook
body: <p>This is a repeated question and I have followed both the suggestions provided in these StackOverflow links:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1386557/how-to-log-out-users-using-facebook-connect-in-php-and-zend/1386749#1386749">How to log-out users using FaceBook connect in php and zend</a></li>
  <li><a href="https://stackoverflow.com/questions/1546277/trouble-logging-out-of-a-facebook-connect-site-and-destroying-sessions">Trouble logging out of a FaceBook connect site and destroying sessions</a></li>
  </ul>
  
  <p>The issue is - the code works 90% of the time. Thats the weird part. Out of the 100 times I've logged in and out - I've experienced this problem 5-6 times and 2 of my beta test users have reported the same issue.</p>
  
  <p>So when it works- if u click the logout link - u get the facebook popup saying - you being logged out - when it does'nt work - absolutely nothing happens - the page does not refresh - it just sits on that page doing nothing.</p>
  
  <p>This is the javascript code that gets called on clicking logout</p>
  
  <pre>
  
  function logout()
  {
     FB.Connect.get_status().waitUntilReady(function(status) {
     switch(status) {
        case FB.ConnectState.connected:
          FB.Connect.logoutAndRedirect("http://www.example.com/login/logout");
          break;
        case FB.ConnectState.userNotLoggedIn:
          window.location = "http://www.example.com/login/logout";
          break;
  }
  });
  return false;          
  }
  
  
  </pre>
  
  <p>This is the php code:</p>
  
  <pre>
  $this->_auth->clearIdentity();
  $face = Zend_Registry::get('facebook');
  $fb = new Facebook($face['appapikey'], $face['appsecret']);
  //$fb->clear_cookie_state();
  $fb->expire_session();
  </pre>
  
  <p>Anyone experienced such sporadic issues.
  Thanks</p>