After logging out of Facebook Connect, the Facebook PHP class still thinks that the user is logged in

When the user first gets to the login screen of my site, I have a "Facebook Connect" function if the user is logged into Facebook and reloads the page if true:

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>

<script type="text/javascript">
  FB.init('MY_API_KEY', '/xd_receiver.htm', { 'reloadIfSessionStateChanged': true });
</script>

      

When the page reloads, my internal PHP code checks to see if the user is logged in to Facebook, and then automatically logs them to my site:

$Facebook = new Facebook(MY_API_KEY, MY_APP_SECRET);

if ($Facebook->get_loggedin_user()) {
  // Log the user in.
}

      

This part works great. The problem is with the logout function. Currently my output link looks like this:

<a href="#" onclick="FB.Connect.logoutAndRedirect('http://my.url/logout/');">Log Out</a>

      

When this is clicked, the user will successfully log out of Facebook, but the Facebook backend PHP object still thinks the user is logged in ( $Facebook->get_loggedin_user()

still returning their user id), so my login code then logs them out again.

So the problem I find is that even though Facebook Connect is logging the user, the Facebook PHP backend still thinks the user is logged in. Does anyone know how to overcome this? Can I automatically login with my PHP code?

Thanks for any help!

+2


source to share


3 answers


I just helped someone with a similar problem. Basically, you need to end your facebook session and then clear the cookies (it's a bit tricky and doesn't explain it all very well in the docs):

How to disconnect users with Facebook Connect in PHP and Zend?



Please vote if it helps;)

+5


source


Since I had to clear my COMPLETE session (the user should be logged out), this worked completely for me:

1.) log out to facebook:

$ redirectUrl = $ this-> getFacebook () -> getLogoutUrl (array (
            'next' => $ this-> baseUrl. '/ logout',
        ));
$ this-> redirect ($ redirectUrl);


2.) log out in my web app after returning from facebook:

public function logoutAction ()
{
        session_destroy ();        
        // redirect back to start page
        return $ this-> redirect ($ this-> baseUrl);
}
+1


source


Can you set up your own variable to flag when this happens as a workaround?

0


source







All Articles