【发布时间】:2015-12-25 11:09:42
【问题描述】:
我正在使用https://github.com/pocesar/facebook-kohana 进行 Facebook 登录。我在注销 Facebook 时遇到问题。它不会破坏 facebook 会话。我已经尝试了很多事情,我已经阅读了很多问题。我在我的注销方法中尝试了这个,但没有结果:
$this->redirect('https://www.facebook.com/logout.php?
next=mysite.dev
&access_token=USER_ACCESS_TOKEN');
我的注销方法是:
public function action_logout(){
$facebook = new Facebook(array(
'appId' => 'appId',
'secret' => 'mySecret',
));
$user = $facebook->getUser();
$facebook->destroySession();
Session::instance()->delete('user');
$this->redirect('/');
}
如何销毁会话,以便用户可以使用另一个 facebook 帐户登录我的网站?谢谢!
我的登录方法是:
public function action_fbLogin(){
$facebook = new Facebook(array(
'appId' => 'appId',
'secret' => 'Secret',
));
$user = $facebook->getUser();
if ($user) {
$user_profile = $facebook->api('/me', array('fields' => 'id,email,name,first_name,last_name,picture'));
$user_id = Model_UserFunctions::checkIfUserExist($user_profile['email']);
if($user_id > 0)
{
Session::instance()->set('user', array(
'fb_id' => $user_profile['id'],
'user_id' => $user_id,
'pic' => $user_profile['picture'],
'email' => $user_profile['email'],
'first_name' => $user_profile['first_name'],
'last_name' => $user_profile['last_name'],
));
//var_dump($_SESSION);
$this->redirect('profile');
exit;
}
$values = array(
'email' => $user_profile['email'],
'username' => $user_profile['email'],
'password' => '12345678'
);
$user = ORM::factory ( 'User' );
$user->values($values);
try
{
if($user->save()){
$user_new_id = $user->as_array();
$user_new_id = $user_new_id['id'];
Session::instance()->set('user', array(
'fb_id' => $user_profile['id'],
'user_id' => $user_new_id,
'pic' => $user_profile['picture'],
'email' => $user_profile['email'],
'first_name' => $user_profile['first_name'],
'last_name' => $user_profile['last_name'],
));
$this->redirect('profile');
}
}
catch (ORM_Validation_Exception $e)
{
$result = $e->errors('models');
echo '<pre>';
print_r($result);
exit;
}
}
else
{
$this->redirect($facebook->getLoginUrl(array('id,email,name,first_name,last_name,picture')));
}
exit;
}
已编辑:我使用 Facebook 注销的目标是因为在我的网站中我只使用 Facebook 登录,没有其他方法可以登录我的网站,这就是它的想法。而且我的网站应该有注销方法,所以当用户想要注销时,他可以做到。 这会从 facebook 注销我,但会显示 facebook 登录页面。如何重定向到我的网站。我已将其设置为下一个,但它不会重定向到它:
<a href="https://www.facebook.com/logout.php?
next=http://mysite.dev
&access_token=Null">Logout</a>
【问题讨论】:
-
但是...他们只需要在 facebook 上使用另一个帐户登录...我认为您不能从您的网站内将他们从他们的 facebook 帐户中注销。
-
这不是从他们的 facebook 注销或只是终止我网站中的 facebook 会话的方式吗? :) 我有 facebook 登录按钮,我设置了会话,这就是我想从我的网站注销用户的原因。
-
请原谅我,但我不明白...如果您将我从您的网站中注销,而我仍然在 Facebook 上登录...那么我会回到您网站上的一个页面仍在使用相同的 FB 帐户,因此您无法使用其他帐户登录。如果我用其他人登录 Facebook,或者我没有在 Facebook 上登录,那么……你可以接受我用其他人登录,或者让我先登录 FB
-
是的,没错。现在,从我的网站注销的唯一方法是从 Facebook 注销。我的问题是,有什么方法可以终止 facebook 会话或使用注销方法从我的网站中的 facebook 注销?
-
@ci_lover — 您能否编辑您的问题以明确说明您的目标是让用户(使用 Facebook 作为身份验证提供商)退出您的网站,而不是让他们退出他们的 Facebook 帐户?
标签: php facebook session kohana logout