views:

182

answers:

0

I'm going to try and distill what's happening down to as little as possible, but still give you all the relevant code. It shouldn't make a difference, but I'm using the Zend Framework. This code executes if the user is not logged in, it fires in a PreDispatch controller plugin:

Zend_Loader::loadClass('Users');
$users = new Users(Zend_Registry::get('dbAdapter'));
if($users->is_facebook_user())
{
    $result = $users->login_facebook_user();

    if($result == 'success')
        $role = $users->role_id;
}

Now this above code is only called if they are not logged in. It does this to check and see if they are logged in to Facebook.

Here is the is_facebook_user() method:

public function is_facebook_user()
{
    $this->fb_userid = $this->fb->get_loggedin_user();

    if($this->fb_userid != '')
    {
        $this->load_user_by_facebook_id($this->fb_userid);
        return true;
    }
    else
        return false;
}

The $fb variable is the official Facebook PHP API class that I downloaded from Facebook. That method basically returns the Facebook User ID. It then calls the a method that pulls the users info from the database. If you look back up at the first block of code you can see that I then call a method to log that user in.

Now, if I watch the traffic using fiddler I see the following series of events: 1. logout url is called, which calls Zend_Auth::getInstance()->clearIdentity(); 2. This then calls the Facebook Logout method, which basically redirects to there site and logs the user out. 3. It then redirects back to the return url that's passed to the Facebook logout method 4. I then see it call the get_loggedin_user again because when it hits back at my site they are logged out.

Here is the problem. I can see that the get_loggedin_user returns a non logged in user, which is the result of this method $this->fb_userid = $this->fb->get_loggedin_user(); but I do get a userid back. So how can my code get this ID, even if I set it to null right before I call this, so there's no way it can be in the code still, and yet somehow watching the traffic I can see it returns a null for the user id, but I somehow get a userid.