简体   繁体   English

如何在CodeIgniter中将Facebook登录页面重定向到同一网站的其他页面?

[英]How can we redirect facebook login page to another page of same website in CodeIgniter?

Controller file. 控制器文件。

public function login()
{
    $userData = array();
    if($this->facebook->is_authenticated())
    {
        $userProfile = $this->facebook->request('get', '/me?fields=id,first_name,last_name,email');
        $userData['oauth_provider'] = 'facebook';
        $userData['oauth_uid'] = $userProfile['id'];
        $userData['firstname'] = $userProfile['first_name'];
        $userData['lastname'] = $userProfile['last_name'];
        $userData['email'] = $userProfile['email'];
        $userData['password'] = rand();
        $userID = $this->user->checkUser($userData);
        if(!empty($userID))
        {
            $data['userData'] = $userData;
            $this->session->set_userdata('userData',$userData);
        } 
        else 
        {
            $data['userData'] = array();
        }
        $data['logoutUrl'] = $this->facebook->logout_url();
    }
    else
    {
        $fbuser = '';
        $data['authUrl'] =  $this->facebook->login_url();
    }
    $data['student_id'] = $this->session->userdata('student_id');
    $this->load->view('header-inside',$data);
    $this->load->view('login',$data);
}

In my code I have created facebook login page in CodeIgniter which is working perfectly. 在我的代码中,我在CodeIgniter中创建了facebook登录页面,该页面运行正常。 When I have login with facebook in my website it have redirect me on the same page but I want to redirect to another page. 当我在我的网站上用facebook登录时,它已将我重定向到同一页面,但我想重定向到另一页面。 So how can I do this? 那我该怎么做呢?

Please help me. 请帮我。

Thank You 谢谢

I suggest you to put redirect('route name') or window.location = "route name" 我建议您放置redirect('route name')或window.location =“ route name”

Assumed that you have route name "home". 假设您的路由名称为“ home”。 in routes.php file such as 在routes.php文件中,例如

routes.php routes.php

$route['home']      = 'cHome/index';

put redirect in your log in success condition after you get userData in session then redirect to home controller and load view inside home controller. 在会话中获取userData之后,将重定向放入成功状态的日志中,然后重定向到主控制器并在主控制器中加载视图。

Controller file 控制器文件

        if(!empty($userID))
        {
            $data['userData'] = $userData;
            $this->session->set_userdata('userData',$userData);
            redirect('home');
        } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM