Facebook – Log out with Facebook Connect in a Cakephp app

cakephpfacebook

I want to include Facebook Connect in a Cakephp app that I'm working on. Right now, I'm trying to implement auto-login with Facebook Connect. I'm able to start a new login session by writing stuff to $this->Session whenever a user's Facebook Connect status is "connected", so I've got the first half of the feature working. The problem comes when the user tries to log off. Like The Run Around demo app, I've got a linke like this:

<a onclick="FB.Connect.logout(redirect_to_logout_action)">log out</a>

The logout action clears the login session variable, but on the next page, the user is still logged in to my site, but not Facebook. The user can log out of my site if he hits the log out link again, so I'm thinking that when he first tries to do this, he gets a new login session on my site, because facebook_client()->get_loggedin_user() is still returning something. Am I doing something wrong here? I thought when my server got the logout request that the Facebook cookies would be cleared by FB.Connect.logout 😕

Best Answer

Have your javascript first do:

FB.Connect.logout

Then

location.href="/logout.php";

And on logout.php have

session_destroy();
session_start();
Related Topic