views:

3367

answers:

5

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

+1  A: 

Have your javascript first do:

FB.Connect.logout

Then

location.href="/logout.php";

And on logout.php have

session_destroy();
session_start();
arbales
I think that's exactly what I'm doing. It might not have been clear, because I had a problem with my question's original markup (i.e. markdown). The part that you probably missed was the <a onclick="FB.Connect.logout(fun)"> tag
allyourcode
A: 

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.

inkedmn
I think I'm doing as both of you expect. I'm exactly using destroy, because there might be other stuff in the session that shouldn't get destroyed. I know that deleting the variable that I'm deleting is the right thing to do to end the login session, because that's how we were doing it before we started integrating FB Connect.
allyourcode
A: 

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

Seth
A: 

i wanna logout,please help me.

nedzad
A: 

Seth: we dont have cakephp, but your steps were tried in simple php, application is also using smarties templating engine. However, didn't work for us :(

Waqar