我正在使用 Facebook PHP-SDK 登录用户,它工作正常。我在正确注销用户时遇到问题。单击注销按钮然后单击登录按钮后,它不会将用户重定向到 Facebook 的登录页面,而是将用户登录到我的网站,就好像注销不成功一样。这是我登录用户的代码:
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");
}
}
这是我的注销代码:
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 + "/");
}
更新:
SDK 使用 native PHP session 并且调用 $this->session->sess_destroy()
不会破坏它,我需要在我的代码中包含 session_destroy()
注销功能。
最佳答案
facebook SDK 使用 native PHP session ,但 codeigniter 不使用。您要做的是在注销方法中添加 session_destroy();
以终止 PHP native session 。
希望对您有所帮助!
关于php - Facebook SDK 注销不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9658406/