2

我正在使用 codeigniter,我有一个控制器,如果他们没有注册,它将登录用户或注册他们,或者如果他们没有登录 Facebook,则提示他们登录 Facebook。

现在我遇到的问题是,如果禁用 cookie,控制器将成功登录它们(我 var_dumped $user 并且很好),然后将它们重定向到另一个控制器,该控制器将显示用户以某种方式注销的页面(var_dump 用户将给出空数组)。

如果我在 facebook 画布之外做同样的事情,一切都很好。

public function login_fb()
    {

        require './assets/fb_sdk/src/facebook.php';
        $facebook = new Facebook(array(
            'appId' => 'app_id',
            'secret' => 'secret id',
            'cookie' => false // i tried it for true as well
        ));

        // See if there is a user from a cookie (even if cookies are disabled it works)
        $user = $facebook->getUser();

        if ($user) {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $user_profile = $facebook->api('/me');
            } catch (FacebookApiException $e) {
                echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
                $user = null;
            }

            $f_id = $user_profile['id'];

 // log in user
                $identity = $f_id;
                $password = "some-password";
                $remember = TRUE; // remember the user
                $this->ion_auth->login($identity, $password, $remember);

                // update token
                $data = array (

                    'access_token'=> $token
                );
                $this->db->where ('username',$f_id);
                $this->db->update ('users',$data);

                $user_ion = $this->ion_auth->user()->row(); 
                //var dump on user_ion will give user information all good



    header('Location: '.base_url().'deals');
}

重定向后,它会丢失所有登录信息和

$user = $this->ion_auth->user()->row();

将给出一个空数组。如果不在 facebook 画布下,这一切都可以正常工作。任何帮助将不胜感激。

4

1 回答 1

0

Set a cookie on the form page where you have the login form. That way you can check if the cookie was set correctly before logging them in.

  • User opens or clicks and gets to login page. Set a cookie, show the form view.
  • User enters login information on the form, and clicks.
  • Before anything else -- Check to see if the cookie was set -- if it was not set then give them an error page with cookies required message.

(ok i don't even know why i was looking at such an old question )

于 2013-11-08T20:56:56.320 回答