简体   繁体   中英

Facebook SDK logout not working

I'm using the Facebook PHP-SDK to sign in users and it works fine. I'm having a problem logging users out correctly. After clicking the logout button and then clicking the sign in button it does not redirect the user to Facebook's sign in page, instead it logs them into my site as if the logout wasn't successful. Here is my code to sign in a user:

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 logout 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 calling $this->session->sess_destroy() would not destroy it, I needed to include session_destroy() in my signout function.

The facebook SDK uses native PHP sessions but codeigniter doesn't. what you want to do is add session_destroy(); in your signout method to kill PHP native session.

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM