注销facebook连接会话
我正在尝试将我的网站与facebook连接集成,以处理facebook注册和facebook登录。我正在使用codeigniter框架。但我现在遇到了这个问题:注销facebook连接会话,facebook,codeigniter,session,connect,logout,Facebook,Codeigniter,Session,Connect,Logout,我正在尝试将我的网站与facebook连接集成,以处理facebook注册和facebook登录。我正在使用codeigniter框架。但我现在遇到了这个问题: 当前facebook登录用户为“test1”。我去我的网站注册facebook,一切正常,“test1”的信息存储在我的数据库中。然而,当我从facebook上注销test1,并在facebook上登录“test2”后,我回到我的网站,再次注册facebook,它仍然保存着“test1”的信息 我使用ion auth库处理用户从我的站点
<?php
include(APPPATH.'libraries/facebook/facebook.php');
class Fb_connect extends Facebook{
//declare public variables
public $user = NULL;
public $user_id = FALSE;
public $fbLoginURL = "";
public $fbLogoutURL = "";
public $fb = FALSE;
public $fbSession = FALSE;
public $appkey = 0;
//constructor method.
public function __construct()
{
$CI = & get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser(); // New code
$me = null;
if ($this->user_id) {
try {
$me = $this->api('/me');
$this->user = $me;
} catch (FacebookApiException $e) {
error_log($e);
}
}
if ($me) {
$this->fbLogoutURL = $this->getLogoutUrl();
} else {
$this->fbLoginURL = $this->getLoginUrl();
}
} //end Fb_connect() function
}
$args['next'] = site_url('logout'); // replace "logout" with your controller which will clear the session
$fbLogoutURL = $facebook->getLogoutUrl($args);
我认为您需要做的是为getLogoutUrl()调用设置“next”参数。大概是这样的:
<?php
include(APPPATH.'libraries/facebook/facebook.php');
class Fb_connect extends Facebook{
//declare public variables
public $user = NULL;
public $user_id = FALSE;
public $fbLoginURL = "";
public $fbLogoutURL = "";
public $fb = FALSE;
public $fbSession = FALSE;
public $appkey = 0;
//constructor method.
public function __construct()
{
$CI = & get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser(); // New code
$me = null;
if ($this->user_id) {
try {
$me = $this->api('/me');
$this->user = $me;
} catch (FacebookApiException $e) {
error_log($e);
}
}
if ($me) {
$this->fbLogoutURL = $this->getLogoutUrl();
} else {
$this->fbLoginURL = $this->getLoginUrl();
}
} //end Fb_connect() function
}
$args['next'] = site_url('logout'); // replace "logout" with your controller which will clear the session
$fbLogoutURL = $facebook->getLogoutUrl($args);
然后,在设置为“next”的控制器中,您需要清除会话数据
class Logout extends CI_Controller {
public function index() {
$facebook->destroySession();
$this->session->sess_destroy(); // Assuming you have session helper loaded
$this->load->view('logout');
}
}
如果有帮助,请告诉我。此外,我认为您还需要在控制器中调用$facebook->destroySession()。(编辑原始帖子以包含此内容)嗨@ametren,是的,事实上,我发现我忘了调用destroysession函数。。。谢谢对不起,尼克,我不知道你指的是什么。你有什么问题需要我帮忙吗?@ametren我试着用$facebook->destroySession()来破坏会话,之后我用了php会话_destroy(),现在它是Wotking哦,是的,我也发现了冗余——很高兴它能工作!