简体   繁体   English

Facebook SDK 注销不起作用

[英]Facebook SDK logout not working

I'm using the Facebook PHP-SDK to sign in users and it works fine.我正在使用 Facebook PHP-SDK 登录用户,它运行良好。 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.单击注销按钮然后单击登录按钮后,它不会将用户重定向到 Facebook 的登录页面,而是将用户登录到我的网站,就好像注销不成功一样。 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. SDK 使用本机 PHP 会话,调用$this->session->sess_destroy()不会破坏它,我需要在我的注销函数中包含session_destroy()

The facebook SDK uses native PHP sessions but codeigniter doesn't. facebook SDK 使用本机 PHP 会话,但 codeigniter 不使用。 what you want to do is add session_destroy();你想要做的是添加session_destroy(); in your signout method to kill PHP native session.在您的注销方法中杀死 PHP 本机会话。

Hope that helps!希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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