views:

2026

answers:

2

When a user first hits my site's login screen, I have Facebook Connect determine if the user is logged into Facebook and reload the page if true:

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

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

When the page is reloaded, my backend PHP code checks if the user is logged into Facebook and then logs them in automatically to my site:

$Facebook = new Facebook(MY_API_KEY, MY_APP_SECRET);

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

That part works fine. The problem is with the logout functionality. My logout link currently looks like this:

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

When that's clicked, the user is successfully logged out of Facebook, but the backend Facebook PHP object still thinks the user is logged in ($Facebook->get_loggedin_user() still returns their user ID), so my login code then logs them in again automatically.

So the problem I'm finding is that even though Facebook Connect logs the user out, the backend Facebook PHP object still considers the user logged in. Does anyone know how to overcome this? Can I not login the user automatically with my PHP code?

Thanks for any help!

A: 

Can you setup a variable of your own to flag when this occurs, as a workaround?

Scooterville
Yeah, I could, but I'd like some more elegant. It seems like my scenario is pretty common? Are others not doing it the way I am?
Justin Stayton
+2  A: 

I just helped someone with a similar issue. Basically, you need to expire the facebook session and then clean up the cookies afterwards (it's a bit tricky and not really explained all that well in the docs):

http://stackoverflow.com/questions/1386557/how-to-log-out-users-using-facebook-connect-in-php-and-zend/1386749#1386749

Vote it up if it helps ;)

Typeoneerror