1
votes

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

3

3 Answers

1
votes

Have your javascript first do:

FB.Connect.logout

Then

location.href="/logout.php";

And on logout.php have

session_destroy();
session_start();
0
votes

As abales said, I would ensure that whatever logout action is being redirected to calls the following method against the CakePHP Session component:

$this->Session->destroy();

That should eliminate the Cake/PHP session. After that, redirect to whatever controller+action is appropriate for a user that isn't logged in.

0
votes

allyourcode,

I had similar issues in an app I built several months ago. We were using the Facebook component (like the one found here: from http://savarino.net/facebook-cakephp).

If I recall correctly, we ended up building a logout method that looked something like this:

$logout_url = $this->Facebook->facebook->get_logout_url('http://' . $_SERVER['SERVER_NAME'] . $this->webroot);
try {
    $this->Facebook->facebook->expire_session();
} catch (Exception $e) {
    $this->Facebook->facebook->set_user(null, null);
    $this->Facebook->facebook->clear_cookie_state();
}

$this->redirect($logout_url);

I'm sorry I cannot be more specific. It's been several months since I've been back inside that app (and several projects since then) but, hopefully this will point you in the right direction.

Seth