我正在使用Facebook Codeigniter PHP SDK。这是我从facebook API获取登录用户的方式:
public $loginuser = "";
function __construct(){
parent::__construct();
/* .......
.......
*/
$fb_config = array(
'appId' => $this->config->item('appID'),
'secret' => $this->config->item('appSecret'),
'default_graph_version' => $this->config->item('graphVersion')
);
$fb = $this->load->library('facebook', $fb_config);
$this->loginuser = $this->facebook->getUser();
}
检查用户是否从Facebook登录:
function index($requestuser, $requestid){
if ($this->loginuser) {
/*do something here */
}else{
$myurl = site_url()."/Crowd/index/".$requestuser."/".$requestid;
redirect($this->facebook->getLoginUrl(array(
'scope' => 'email,user_likes,user_friends',
'redirect_uri' => $myurl
)));
}
}
我遇到两个问题:
从Facebook(而不是从应用程序)注销时,应用程序上的会话和cookie不会被销毁,因此即使用户已从Facebook注销,也会将用户视为已登录。
从应用程序注销时,会话也不会被销毁。
这是注销网址:
$logout_url = $this->facebook->getLogoutUrl(array('next' => site_url() . '/user/logout'));
以下是User/logout
控制器内部的操作:
public function logout(){
$this->session->unset_userdata('id');
$this->session->unset_userdata('email');
$this->session->unset_userdata('firstname');
$this->session->unset_userdata('lastname');
$this->session->unset_userdata('status');
$this->session->unset_userdata('isLoggedIn');
$this->session->sess_destroy();
session_destroy();
// Redirect to baseurl
redirect(base_url());
//redirect('login/index');
}
如何查看已登录的用户?以及如何在退出时销毁Facebook登录会话?
答案 0 :(得分:1)
检查用户是否仍然登录他/她的Facebook帐户
if ($facebook->getUser())
{
try
{
$user = $facebook->api('/me');
//continue
}
catch(FacebookApiException $e){
$facebook->destroySession();
//destroy
}
}