简体   繁体   中英

Page doesn't redirect after Facebook login in CodeIgniter

I'm using this code ( codeigniter-facebook-php-sdk-v4 ) to connect my controller to Facebook login. Mycontroller :

public function index() {
    //load views
    $this->load->view('pages/header');
    $this->load->view('pages/index'); //contains a href of mycontroller/facebook_login
    $this->load->view('pages/footer');
}

public function facebook_login() {
    $fb_data = $this->lib_facebook->facebook();

    if (isset($fb_data['me'])) {
         //save fb user data
    }
}

After, the data is saved, the browser is still mycontroller/facebook_login page. I want it to redirect it to the index page.

Facebook\\FacebookRedirectLoginHelper

If your web app uses Facebook Login on the back-end, you'll need to redirect your visitors to a URL at Facebook to initiate a login request. Facebook then redirects the user to your apps callback URL, providing session data. This helper class will generate the login URL for you, and can process and validate the data from Facebook, returning a FacebookSession on success.

Remember when you set your callback URL ? Yes, change that before you do the request.

// change the url before you make the request
$desired_url = 'url_desired'; // set the url you want the user to be redirected after logging in
$helper = new FacebookRedirectLoginHelper($desired_url); 

And then you can simply use

echo '<a href="' . $helper->getLoginUrl() . '">Login with Facebook</a>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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