Logging out of Facebook doesn't work

I am using PHP-SDK for login and it works great. I'm having problems registering users. After clicking the logout button and clicking the login button, it doesn't redirect the user to the Facebook login page, instead it logs them to my site as if the logout was unsuccessful. Here is my user login code:

function authenticate_user()
{
    $CI = & get_instance();
    $CI->config->load("facebook",TRUE);
    $config = $CI->config->item('facebook');
    $CI->load->library('facebook', $config);

    $user = $CI->facebook->getUser();

    if ($user)
    {
        try
        {
            $user_profile = $CI->facebook->api('/me');
            return $user_profile;
        }
        catch (FacebookApiException $e)
        {
            error_log($e);
        }
    }

    return FALSE;

}

public function signin()
{
    $user_profile = authenticate_user();
    if (!$user_profile)
    {   
        $loginUrl = $this->facebook->getLoginUrl(array('scope' => 'email'));
        redirect($loginUrl);
    }

    $this->load->model("user_model");

    if ($userRow = $this->user_model->user_exists($user_profile["id"]))
    {
        set_session($user_profile, $userRow->privileges);
        redirect("member_controller/members");
    }
}

      

This is my exit code:

public function fb_signout()
{
    $params = array( 'next' => 'http://www.' + $host + '/index.php/authentication_controller/signout');
    redirect($this->facebook->getLogoutUrl($params)); // $params is optional.
}

public function signout()
{
    $this->session->sess_destroy();
    redirect("http://www." + $host + "/");
}

      

UPDATE:

The SDK was using native PHP sessions and the call $this->session->sess_destroy()

will not destroy it, I need to include session_destroy()

in my signout function.

+3


source to share


1 answer


Facebook SDK uses native PHP sessions, but codinigregister doesn't work. what you want to do is add session_destroy();

pins to your controller to kill the native PHP session.



Hope it helps!

+3


source







All Articles