我正在使用 https://github.com/pocesar/facebook-kohana
登录 Facebook。我有 facebook 注销的问题。它不会破坏 facebook session 。我尝试了很多东西,也读过很多问题。我在我的注销方法中试过这个,但没有结果:
ojit_代码
我的注销方法是:
public function action_logout(){
$facebook = new Facebook(array(
'appId' => 'appId',
'secret' => 'mySecret',
));
$user = $facebook->getUser();
$facebook->destroySession();
Session::instance()->delete('user');
$this->redirect('/');
}
如何销毁 session ,以便用户可以使用另一个 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 登录页面。如何重定向到我的网站旁边。我已将它设置为下一个,但它不会重定向到它:
$this->redirect('https://www.facebook.com/logout.php?
next=mysite.dev
&access_token=USER_ACCESS_TOKEN');
最佳答案
您可以使用 facebook-php-sdk API 获取 facebook 注销 url。 当用户单击该 url 时,他的 Facebook 帐户将处于离线状态。
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
有关更多信息,您可以查看此网址。
关于php - 如何在我的网站上退出 facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32819093/