php - 如何在我的网站上退出 facebook

标签 php facebook session kohana logout

我正在使用 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();
}

有关更多信息,您可以查看此网址。

https://github.com/facebookarchive/facebook-php-sdk

关于php - 如何在我的网站上退出 facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32819093/

相关文章:

php - 使用 PHP 将 Basename 应用于 CSS 类,但索引页面出错

php - CakePHP View 中的 Javascript 导致 Controller 操作被调用两次

javascript - 如何回显 JS 重定向?

facebook - 我可以通过 api 获得 facebook 组墙帖子吗?

android - 尝试为具有挂起请求的 session 请求新权限

facebook - fatal error : Uncaught OAuthException: (#803) Some of the aliases you requested do not exist

node.js - 在 Express 中, session Cookie 过期太早

php - 这个 PHP(函数/构造?)是做什么的,我在哪里可以找到更多关于它的文档?

php - 文件和文件夹必须可由登录用户访问。如何保护文件免遭未经授权的访问

session - tomcat/jboss session 存储