开发者

After Facebook Connect logout, Facebook PHP class still thinks user is logged in

When a user first hits my site's login screen, I h开发者_如何转开发ave 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"></script>

<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/');">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!


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):

How to log out users using Facebook Connect in PHP and Zend?

Vote it up if it helps ;)


Since I had to clear my COMPLETE session (user has to be logged out), this worked totally fine for me:

1.) log out user at facebook:

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

2.) log out the user at my web app, after the bounce back from facebook:

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜