title: Trouble logging out of a Facebook connect site and destroying sessions
body: <p>I can't seem to get a facebook connect app that I am building to log the user out (sorry no url as it's still in dev). Each time the user clicks a link with the class "logout" the following JS runs which seems to work and even shows the FB modal stating the user has been logged out.</p>
  
  <pre><code>$(document).ready(function(){
      $('.logout').click(function(){
          //Kill facebook Session
          FB.Connect.logout(function() {
              window.location = $('.logout').attr("href");
          });
      });
  });
  </code></pre>
  
  <p>Upon reaching the callback above, the JS sends the user to the logout page where PHP again forces the removal of a custom session and insures that the FB session was removed. Then the user is sent back to the page they were on when they clicked the "logout" link.</p>
  
  <pre><code>//Remove our site session
  Auth::logout();
  
  
  
  /* FAIL
  //Send user to FB logout page and then back here
  $logout_url = $this-&gt;fb-&gt;get_logout_url( site_url( $return_to ? base64_url_decode($return_to) : '' ) );
  
  // Clear any stored state
  $this-&gt;fb-&gt;clear_cookie_state();
  
  exit(header("Location: ". $logout_url));
  */
  
  
  
  //FAIL
  //$this-&gt;fb-&gt;logout( site_url( $return_to ? base64_url_decode($return_to) : '' ) );
  
  
  //FAIL
  //Remove user (is this needed..?)
  //$this-&gt;fb-&gt;set_user(NULL, NULL);
  
  
  //Remove the FB session cookies (in case the JS didn't)
  $this-&gt;fb-&gt;clear_cookie_state();
  
  
  // Redirect to privious page
  redirect( ( $return_to ? base64_url_decode($return_to) : '') );
  </code></pre>
  
  <p>However, this whole process results in the user being right back where they were and still logged in. A second click on the link seems to do the trick and remove the session though. I have monitored firebug (w/firecookie) and the PHP logout page reports deleting the FB session cookies - yet the next page loaded seems to still use them?!</p>
  
  <p>If anyone knows how to completely <strike>DESTROY ALL FACEBOOKS</strike> ahem... sessions then please speak up.</p>
  
  <p>:EDIT:
  I have even tried to manually remove all cookies on the logout page and it still fails</p>
  
  <pre><code>if( $_COOKIE ) {
  
      foreach( $_COOKIE as $name =&gt; $value ) {
  
          //Get the current cookie config
          $params = session_get_cookie_params();
  
          // Delete the cookie from globals
          unset($_COOKIE[$name]);
  
          //Delete the cookie on the user_agent
          setcookie($name, '', time()-43200, $params['path'], '', $params['secure']);
      }
  }
  </code></pre>