如何使用Facebook登录在Kohana中销毁会话

时间:2015-09-27 11:48:27

标签: php facebook session kohana logout

我使用Facebook登录我的网站。我使用的是Kohana 3.3.1。我有登出方法。当我在注销后var_dump($ _ SESSION)时,它是空数组。但问题是,当我从网站退出并尝试使用其他Facebook帐户再次登录我的网站时,它无法显示Facebook弹出窗口,我无法登录此帐户。它仍然显示以前帐户的数据。并且facebook按钮仍然具有登录标题,它根本不显示登出标题。

如何完全破坏Facebook会话,以便我能够使用其他Facebook帐户登录?提前谢谢!

我的登录按钮是:



<a href="<?php echo URL::base(); ?>membership/logout">Logout</a>
&#13;
&#13;
&#13;

这是我登录的方法:

&#13;
&#13;
public function action_fbLogin(){
      
        $facebook = new Facebook(array(
            'appId'  => 'MyAppId',
            'secret' => 'MYSecret',
        ));

        $user = $facebook->getUser();
        if ($user) {

            $user_profile = $facebook->api('/me', array('fields' => 'id,email,name,first_name,last_name,picture')); 
           var_dump($user_profile);
            $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;
    
    }
&#13;
&#13;
&#13;

我的注销方法是:

&#13;
&#13;
public  function action_logout(){
        Session::instance()->delete('user');
       // var_dump($_SESSION);
        $this->redirect('/');
    }
&#13;
&#13;
&#13;

0 个答案:

没有答案