如何在我的网站上从Facebook注销 [英] How to log out from facebook in my site

查看:133
本文介绍了如何在我的网站上从Facebook注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using https://github.com/pocesar/facebook-kohana for facebook login. I have problem with facebook logout. It doesn't destroy facebook session. I've tried so many things and I've read many questions. I tried this in my logout method, but no result: $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帐户登录我的网站?谢谢!

How to destroy session, so that user can log in my site with another facebook account? Thanks!

我的方法登录名是:

 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登录页面.如何重定向到我的网站旁边.我将其设置为下一个,但它不会重定向到它:

Edited: My goal to use Facebook logout is because in my site I only use Facebook login, there isn't another way to log in my site, that's idea of it. And I should have logout method in my site, so when user wants to logout, he could do it. This logouts me from facebook but facebook login page is shown. How to redirect next to my site. I've set it as next but it doesn't redirect to it:

<a href="https://www.facebook.com/logout.php? next=http://mysite.dev &access_token=Null">Logout</a>

<a href="https://www.facebook.com/logout.php? next=http://mysite.dev &access_token=Null">Logout</a>

推荐答案

那么您对Facebook没问题

Then you don't have a problem with facebook

只有需要销毁的会话...

Is only the session that needs to be destroyed...

在PHP手册的此页面上,有一个示例显示您可能需要其他步骤才能破坏unset($_SESSION)

On this page of PHP manual there is an example showing you might need aditional steps to destroy a session beyond unset($_SESSION)

http://php.net/manual/en/function.session- destroy.php

强迫用户从Facebook注销对我来说并不是一个好举动.

Forcing the users to log off from Facebook does not seem a good move for me.

数百万的FB用户有意要求保持登录状态,并且如果他们访问您的站点并从那里注销,他们可能会认为注销FB帐户对您不是很友好.许多人甚至都不记得他们的密码...所以您将为他们制造一个问题,他们可能永远不会回到您的网站...只是说

Millions of FB users have intentionally asked to stay logged in and if they visit your site and logoff from there they might think it wasn't very friendly of you to log them off the FB accounts. many don't even remember their pwd... so you would be creating a problem for them and they might never comeback to your site... Just saying

这篇关于如何在我的网站上从Facebook注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆