Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login with Codeigniter stopped working suddenly

I am using Facebook with Codeigniter and was working fine but suddenly stopped working, is facebook changed anything

the facebook function

public function takofacebook($page = TRUE, $name = TRUE) {

    if (isset($page) and (($page != TRUE) or ($page != 1)) and isset($name)) {
        $data['page'] = $page;
        $data['name'] = $name;
    }

    $this -> load -> library('fb');
    if (!$this -> fb -> is_connected()) {
        redirect($this -> fb -> login_url(current_url()));
    }

    $fb_user = $this -> fb -> client -> api('/me');

    if (empty($fb_user)) {
        $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
        $this -> session -> set_flashdata('register_error', $error);
    } else {
        $this -> user -> set_facebook_id($fb_user['id']);
        $user = $this -> user -> get_by_facebook();
        if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {

            //TODO: Make things a bit more secure here
            //Login & Redirect home

            $this -> _login($user -> id, 'facebook');
            $this -> load -> view('users/redirect_home2', $data);
            return;
        }
    }
    //Go to the registeration page
    $this -> load -> view('users/redirect2', array('method' => 'facebook'));
}

/**
 * Logs user in with facebook
 */

 //tako facebook
public function zangafacebook() {



    $this -> load -> library('fb');
    if (!$this -> fb -> is_connected()) {
        redirect($this -> fb -> login_url(current_url()));
    }

    $fb_user = $this -> fb -> client -> api('/me');

    if (empty($fb_user)) {
        $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
        $this -> session -> set_flashdata('register_error', $error);
    } else {
        $this -> user -> set_facebook_id($fb_user['id']);
        $user = $this -> user -> get_by_facebook();
        if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {

            //TODO: Make things a bit more secure here
            //Login & Redirect home

            $this -> _login($user -> id, 'facebook');
            $this -> load -> view('users/redirect_home3');
            return;
        }
    }
    //Go to the registeration page
    $this -> load -> view('users/redirect3', array('method' => 'facebook'));
}
like image 218
Nadia Nasim Shomali Yacoub Avatar asked Dec 04 '25 16:12

Nadia Nasim Shomali Yacoub


1 Answers

I tested the official php sdk from Facebook that is on my CodeIgniter site and it works fine. Is $fb_user empty? Where is the error? Are you using the official PHP SDK for Facebook? There are a lot of variables to figure out what is going wrong here. Like ifaour suggests, use the official php sdk here if you are not already: https://github.com/facebook/facebook-php-sdk/tree/master/src

Drop the files in the library directory and call it normally

$this -> load -> library('facebook');

Then you can get the facebook data like this:

$fb_user = $this -> facebook -> api('/me');

again I am not sure where your error is so are you missing a parameter here?

$user = $this -> user -> get_by_facebook($fb_user['id']);

This is all I am doing on my site and it is working just fine. This also has the benifit that if Facebook does change anything you just need to download the new SDK and your code should remain unchanged.

like image 82
dasper Avatar answered Dec 10 '25 18:12

dasper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!