[英]Facebook logout not working with PHP SDK
I know this has been asked many times before and I've spent about 2 hours now trawling through every other answer and trying out solutions and none of them have worked. 我知道这个问题以前曾被问过很多遍,现在我花了大约2个小时来浏览其他所有答案并尝试解决方案,但没有一个起作用。 Basically the problem is I am using the Facebook PHP SDK to log my user in. That bit is fine.
基本上,问题是我正在使用Facebook PHP SDK登录用户。那很好。 When I want to log the user out of my site and Facebook though it doesn't work.
当我想将用户从我的网站和Facebook注销时,尽管它不起作用。 My site is built in codeigniter if that affects anything.
如果这会影响任何内容,则我的网站将内置在codeigniter中。 Here is what I have:
这是我所拥有的:
$this->load->library('facebook');
$logout_url = $this->facebook->getLogoutUrl(array('next' => site_url()));
redirect($logout_url);
This user gets redirected ok but if I go to facebook.com I am still logged in. This should log the user out of facebook as well should it not? 可以将该用户重定向到ok,但是如果我转到facebook.com,我仍然可以登录。这也应该使该用户退出facebook,不是吗? I have tried alsorts such as clearing the native php session, unsetting cookies etc. like so:
我已经尝试过Alsorts,例如清除本地php会话,取消设置cookie等,如下所示:
$config = array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'fileUpload' => true, // Indicates if the CURL based @ syntax for file uploads is enabled.
);
$this->load->library('facebook', $config);
setcookie('fbs_'.$this->facebook->getAppId(), '', time()-100, '/', $_SERVER["SERVER_NAME"]);
unset($_SESSION['fb_'.$this->facebook->getAppId().'_code']);
unset($_SESSION['fb_'.$this->facebook->getAppId().'_access_token']);
unset($_SESSION['fb_'.$this->facebook->getAppId().'_user_id']);
unset($_SESSION['fb_'.$this->facebook->getAppId().'_state']);
$logout_url = $this->facebook->getLogoutUrl();
$this->facebook->destroySession();
try {
$this->facebook->destroySession();
setcookie('fbs_'.$this->facebook->getAppId(), '', time()-100, '/', base_url());
} catch (Exception $e) {
//$this->facebook->clearAllPersistentData(); Protected method
}
$this->session->sess_destroy();
So the only thing I can think is that there is a bug with Facebook at their end and its not logging out when it should. 因此,我唯一能想到的是,Facebook的一端存在一个错误,并且该错误在适当的时候没有注销。 Anyone know if this is the case?
有人知道是这样吗?
Codeigniter doesn't use native PHP sessions - CI stores sessions in a cookie. Codeigniter不使用本机PHP会话-CI将会话存储在cookie中。 You can read about it here .
你可以在这里阅读。
Facebook, however, does use native PHP sessions. 但是,Facebook确实使用本机PHP会话。 So what you'll find is destroying the Codeigniter session won't destroy the Facebook session.
因此,您将发现破坏Codeigniter会话不会破坏Facebook会话。
You could try something like this: 您可以尝试这样的事情:
// Destroy CodeIgniter Session
$this->session->sess_destroy();
// Destroy Facebook Session using Facebook function
$this->facebok->destroySession();
// Maybe even destroy all native sessions as overkill
session_destroy();
I imagine after doing this, there's no way the session will/can still persist. 我想在完成此操作之后,会话将无法/仍将继续。 This happens all the time with PHP and Codeigniter.
PHP和Codeigniter始终会发生这种情况。 See: logout facebook connect session
请参阅: 注销Facebook Connect会话
I fixed my issue by commenting out the line below. 我通过注释下面的行来解决我的问题。 Now my users can logout.
现在我的用户可以注销了。
$this->facebook->destroySession();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.