Facebook Connect User Authentication using the new Graph API in CodeIgniter Oct 5, 2010

The User Experience is a very important element of system design.  At HitSend Inc., we really try to make that experience easy and intuitive for our users.

With this in mind, we knew our users would need to have user profiles to access our system.  However, we did not want to force them to create another username and password to remember.  So from the beginning we knew we wanted to capitalize on the robust authentication systems already created!

This tutorial will show how we use the new Facebook Connect Graph API to supplement our authentication system using the CodeIgniter PHP framework.

First, I want to thank Elliot Haughin for his work in creating a Facebook Connect CodeIgniter framework that helped get ours up and running fairly quickly.  (Actually, it is because of his that I have decided to release this to the wild, in the hopes that someone comes along and makes an even better one that I can use!).

To make this tutorial as simple as possible, I’ve assume that you have basic knowledge of the CodeIgniter framework and have looked into the Facebook API documentation (… at least a little bit…)

Alright, let’s get down to business!

This tutorial is split into a few parts:

  1. A brief overview on creating a Facebook application
  2. A simple user table for your database
  3. Setting up the config parameters and creating a library
  4. Using the PHP and Javascript APIs with your login code.
  5. Download the Source


1. Create a Facebook Application

The first thing you need to do is create a Facebook application.  There are tons of tutorials out there for doing this, so I won’t belabour this section.  Facebook have a pretty decent walk through for creating an app here.  Once you have created your app, make note of the api keysecret key and the site url.  We will be using these later on in the tutorial.

Here is an image of what my application settings look like:

The Site URL is the root location of your site, and the Site Domain is (as you would think) the domain of your site.  When setting up the application using the app id and secret key from a domain different from one you specified in the Site Domain field will cause an error.  So make sure this part is set up right before you continue.

Moving on…

2. Database schema

Again, for simplicity sake, here is what our user table looks like.  In a real system we would capture a lot more information than this.

CREATE TABLE user (
	user_id      VARCHAR(100),
	full_name  VARCHAR(100),
	pwd             VARCHAR(100),
	fb_uid        VARCHAR(100),
);

The fields are pretty self explanatory.   The ‘user_id’ is what the user would log in as.  The ‘pwd’ field is the user’s password (ideally encrypted, to keep the data secure), the ‘full_name’ is just another field you can capture.  You can add more fields to this table like,  email address, birthday, or whatever else you want to capture in your system.

The  ‘fb_uid’ field will be the user’s Facebook account id that will be populated through Facebook, and is how we authenticate a person into our system through Facebook.

3. Creating the CodeIgniter facebook configuration and library

The facebook configuration is used to store the users api key and secret key.

You will also need to create a file ‘facebook.php‘ in the ‘application/config/‘ folder.  It only contains the following 3 lines:

<?php
$config['facebook_api_key'] = 'your_facebook_api_key';
$config['facebook_secret_key'] = 'your_facebook_secret_key';

Creating a CodeIgniter library is the simplest way to integrate the Facebook Graph API into our system.

Download the latest PHP Facebook API from http://github.com/facebook/php-sdk/All you really need from here is the facebook.php file.

Create a new directory called ‘facebook‘ under ‘application/libraries/’ and place this facebook.php file here.

Now create a PHP file called ‘fb_connect.php‘ in the ‘application/libraries/‘.

Below is the code for this PHP file:  (it is pretty simple, although it might be easier to read through the sample code.)

<?php
//fb_connect.php
//Author: Graham McCarthy,  HitSend Inc., September 29th, 2010
//Email: graham@hitsend.ca
//Description: facebook connect library, connects to facebook and
//    stores all the required information in return variables
//grab the facebook api php file
include(APPPATH.'libraries/facebook/facebook.php');

class Fb_connect {
//declare variables
private $_obj;
private $_api_key        = NULL;
private $_secret_key    = NULL;

public     $user             = NULL;
public     $user_id         = FALSE;

public $fbLoginURL     = "";
public $fbLogoutURL = "";

public $fb             = FALSE;
public $fbSession    = FALSE;
public $appkey        = 0;

//constructor method.
function Fb_connect()
{
//Using the CodeIgniter object, rather than creating a copy of it
$this->_obj =& get_instance();

//loading the config paramters for facebook (where we stored our Facebook API and SECRET keys
$this->_obj->load->config('facebook');
//make sure the session library is initiated. may have already done this in another method.
$this->_obj->load->library('session');

//
$this->_api_key        = $this->_obj->config->item('facebook_api_key');
$this->_secret_key    = $this->_obj->config->item('facebook_secret_key');

$this->appkey = $this->_api_key;

//connect to facebook
$this->fb = new Facebook(array(
'appId'  => $this->_api_key,
'secret' => $this->_secret_key,
'cookie' => true,
));

//store the return session from facebook
$this->fbSession  = $this->fb->getSession();

$me = null;
// If a valid fbSession is returned, try to get the user information contained within.
if ($this->fbSession) {
try {
//get information from the fb object
$uid = $this->fb->getUser();
$me = $this->fb->api('/me');

$this->user = $me;
$this->user_id = $uid;

} catch (FacebookApiException $e) {
error_log($e);
}
}

// login or logout url will be needed depending on current user state.
//(if using the javascript api as well, you may not need these.)
if ($me) {
$this->fbLogoutURL = $this->fb->getLogoutUrl();
} else {
$this->fbLoginURL = $this->fb->getLoginUrl();
}
} //end Fb_connect() function
} // end class

4. Setting up the Login

The reason for creating the library ‘fb_connect’ is that whenever we want to access the facebook api, all we need to do in our controller is load the library:

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

Then in our controller code we can make calls like:

$this->fb_connect->user_id; // returns the logged in users id
$this->fb_connect->user; // returns an object containing all the user data.

You can also check if you have a valid and authenticated facebook session like this:

if($this->fb_connect->fbSession) {

// logged in just fine

} else  {

//Not Logged in

}

The Login Controller and view can get a little messy.  I’ll assume you’ve already created a login that validates by using the user_id and pwd.  Again, there are plenty of tutorials around that cover this sort of interaction.  NetTuts have a very easy to follow tutorial.

Logging in through Facebook skips this process.

It compares the item returned by $this->fb_connect->user_id to the fb_uid field in the user table.

Here is what a sample login.php controller looks like:

<?php
class Login extends Controller {
function Login() {
parent::Controller();
$this->load->model('user_model');
}

function index() {
//create blank data array to return
$data = array();

$this->load->library('fb_connect');
$data = array(
'facebook'        => $this->fb_connect->fb,
'fbSession'        => $this->fb_connect->fbSession,
'user'            => $this->fb_connect->user,
'uid'            => $this->fb_connect->user_id,
'fbLogoutURL'    => $this->fb_connect->fbLogoutURL,
'fbLoginURL'    => $this->fb_connect->fbLoginURL,
'base_url'        => site_url('login/facebook'),
'appkey'        => $this->fb_connect->appkey,
);

$this->load->view('login_view', $data);
}

//This won't destroy your facebook session
function logout() {
$this->session->sess_destroy();
$data['logged_out'] = TRUE;
//$this->index($data);
redirect('/login/index');
} // function logout()

function _facebook_validate($uid = 0) {
//this query basically sees if the users facebook user id is associated with a user.
$bQry = $this->user_model->validate_user_facebook($uid);

if($bQry) { // if the user's credentials validated...
$data = array(
'user_id' => $uid,
'is_logged_in' => true,
'list_type' => 'hot'
);

$this->session->set_userdata($data);

$uri_var = $this->uri->segment(3);

if (strlen($uri_var) > 0 ){
$url_location = $uri_var;
$url_location = str_replace('-', '/', $url_location);
redirect($url_location);
} else{
redirect('/message/index');
}

} else {
// incorrect username or password
$data = array();
$data["login_failed"] = TRUE;
$this->index($data);
}
}

function facebook() {
//1. Check to see if the facebook session has been declared
$this->load->library('fb_connect');

if(!$this->fb_connect->fbSession) {
//2. If No, bounce back to login
$this->index();
} else {

$fb_uid = $this->fb_connect->user_id;
$fb_usr = $this->fb_connect->user;

if($fb_uid != false) {
//3. If yes, see if the facebook id is associated with any existing account
$usr = $this->user_model->get_user_by_fb_uid($fb_uid);

if( is_array($usr) && count($usr) == 1) {
$usr = $usr[0];
//3.a. if yes, log the person in
//echo "Logging in via facebook...";
$this->_facebook_validate($usr->user_id);

} else {
//3.b. if no, register the new user.
//echo "Creating a new account...";
//search for missing data and notify the user of what is missing.
$fname = $fb_usr["first_name"];
$lname = $fb_usr["last_name"];
$fullname = $fb_usr["name"];
$pwd = ''; //left blank so user can modify this later
$email = $fb_usr["email"];
//$fb_uid = already defined.

$db_values = array (
'user_id' => "fb:".$fb_uid,
'fb_uid' => "fb:".$fb_uid,
'full_name' => $fullname,
'pwd' => "",
);

//data ready, try to create the new user
if($query = $this->user_model->create_user($db_values) ) {
$data['account_created'] = true;
//log user in
$this->_facebook_validate($db_values["user_id"]);
} else {
//Did not work, go back to login page
$this->index();
}
}
}
}
}
}

This controller includes a model called ‘user_model.php‘.  Here is the code for that model:

<?php
class User_model extends Model {
var $user_id = "";
var $full_name = "";
var $pwd = "";
var $fb_uid = "";

function User_model() {
//Call the Model constructor
parent::Model();

}

function validate_user_facebook($uid = 0) {
//confirm that facebook session data is still valid and matches
$this->load->library('fb_connect');

//see if the facebook session is valid and the user id in the sesison is equal to the user_id you want to validate
$session_uid = 'fb:' .  $this->fb_connect->fbSession['uid'];
if(!$this->fb_connect->fbSession || $session_uid != $uid ) {
return false;
}

//Receive Data
$this->user_id    = $uid;

//See if User exists
$this->db->where('user_id', $this->user_id);
$q = $this->db->get('users');

if($q->num_rows == 1) {
//yes, a user exists,
return true;
}

//no user exists
return false;
}

function create_user($db_values = '') {
$this->user_id       = $db_values["user_id"];
$this->full_name  = $db_values["full_name"];
$this->pwd           = md5($db_values["pwd"]);
if(strlen($db_values['fb_uid']) > 0) {
$this->fb_uid        = $db_values['fb_uid'];
} else {
$this->fb_uid = "";
}

$new_user_data = array(
'user_id'  => $this->user_id,
'full_name'  => $this->full_name,
'pwd'      => $this->pwd,
'fb_uid' => $this->fb_uid,
);

$insert = $this->db->insert('users', $new_user_data);

return $insert;
}

function get_user_by_fb_uid($fb_uid = 0) {
//returns the facebook user as an array.
$sql = " SELECT * FROM SV_users WHERE 0 = 0 AND fb_uid = ?";
$usr_qry = $this->db->query($sql, array('fb:'.$fb_uid));

if($usr_qry->num_rows == 1) {
//yes, a user exists
return $usr_qry->result();
} else {
// no user exists
return false;
}
}
}

The login.php controller links to a view called login_view.php.  Here is what it looks like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SoapBox Login</title>
</head>
<body>
<!-- FB CODE -->
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '<?=$appkey?>', status: true, cookie: true, xfbml: true});

/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
// do something with response
login();
});

FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
};

(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());

function login(){
document.location.href = "<?=$base_url?>";
}

function logout(){
document.location.href = "<?=$base_url?>";
}
</script>
<!-- END OF FB CODE -->

<form action="<?php echo site_url('login/validate_user/') . '/' . $uri_var;?>" method="post">
<p>username:<br /><?= form_input('user_id', '') ?></p>
<p>password:<br /><?= form_password('pwd', '') ?></p>

<p id="buttons">
<fb:login-button onlogin="login();" size="medium" perms="email,offline_access,user_birthday,status_update,publish_stream">Connect</fb:login-button>

<?= form_submit('submit', 'Login') ?>
</p>
</form>
</body>
</html>

5. Download the Source

It might be a little tricky copy and pasting the code in this tutorial.  So feel free to download the sample source.  It is fairly documented, and should show you how to integrate a login system with Facebook

If you have any questions or problems, or if you have a better way to integrate Facebook authentication in your system, please leave a comment!

Cheers,

Graham McCarthy.  HitSend Inc.

  • Dave

    By the looks of it you have a small error in your model the construct has the wrong name

  • Dave

    By the looks of it you have a small error in your model the construct has the wrong name

  • http://twitter.com/grahammccarthy Graham McCarthy

    Thanks Dave! I have fixed the typo.

  • http://twitter.com/grahammccarthy Graham McCarthy

    Thanks Dave! I have fixed the typo.

  • Anonymous

    Just posted a link to this tutorial in the Facebook Group PHP CodeIgniter Excellence. Thanks for sharing.

  • Anonymous

    Just posted a link to this tutorial in the Facebook Group PHP CodeIgniter Excellence. Thanks for sharing.

  • Indublin2008

    form in login_view is posted to ‘login/validate_user’…but I don’t see the validate_user function in the login controller ?!

  • Indublin2008

    form in login_view is posted to ‘login/validate_user’…but I don’t see the validate_user function in the login controller ?!

  • http://twitter.com/grahammccarthy Graham McCarthy

    Hi Indublin2008, we didn’t include the validate_user function in our demo because it wasn’t really necessary. That function would have handled the traditional user authentication. Accepting in a username and password and validating against the database. The facebook connect button takes over this functionality and that is what we wanted to highlight.

    I hope that clarifies things.

    Cheers,

  • http://twitter.com/grahammccarthy Graham McCarthy

    Hi Indublin2008, we didn’t include the validate_user function in our demo because it wasn’t really necessary. That function would have handled the traditional user authentication. Accepting in a username and password and validating against the database. The facebook connect button takes over this functionality and that is what we wanted to highlight.

    I hope that clarifies things.

    Cheers,

  • http://www.facebook.com/profile.php?id=564981046 Robert Lord

    Is it just me who gets “The URI you submitted has disallowed characters.” when getting redirected back from Facebook to the the application?

  • http://www.facebook.com/profile.php?id=564981046 Robert Lord

    Is it just me who gets “The URI you submitted has disallowed characters.” when getting redirected back from Facebook to the the application?

  • http://www.facebook.com/profile.php?id=564981046 Robert Lord

    Solved by changing a line in the application/config/config.php file:

    $config['uri_protocol'] = “PATH_INFO”;

  • http://www.facebook.com/profile.php?id=564981046 Robert Lord

    Solved by changing a line in the application/config/config.php file:

    $config['uri_protocol'] = “PATH_INFO”;

  • http://twitter.com/grahammccarthy Graham McCarthy

    Glad you got it fixed.

  • http://twitter.com/grahammccarthy Graham McCarthy

    Glad you got it fixed.

  • http://buzzknow.com Buzzknow

    This is really fresh tutz for fb connect, since fb very often update their library and other tutorial has no update … so this tutz really great!

    Thanks

  • http://buzzknow.com Buzzknow

    This is really fresh tutz for fb connect, since fb very often update their library and other tutorial has no update … so this tutz really great!

    Thanks

  • http://www.facebook.com/people/Venkatperfect-Koti/1496171866 Venkatperfect Koti

    How to show User Picture from Facebook in my view?

  • http://www.facebook.com/people/Venkatperfect-Koti/1496171866 Venkatperfect Koti

    How to show User Picture from Facebook in my view?

  • Shrinimann

    I get the following error, when i try to implement the above tutorial:

    PHP Error was encountered

    Severity: Notice

    Message: Undefined variable: uri_var

    Filename: views/login_view.php

    Line Number: 47

    http://localhost:8888/login/validate_user/” method=”post”>

    the code here is: ” <form action="” method=”post”>

    can someoen please help me? do i have to declare the variable in here or is it passed by the facebook return method?

  • Shrinimann

    I get the following error, when i try to implement the above tutorial:

    PHP Error was encountered

    Severity: Notice

    Message: Undefined variable: uri_var

    Filename: views/login_view.php

    Line Number: 47

    http://localhost:8888/login/validate_user/” method=”post”>

    the code here is: ” <form action="” method=”post”>

    can someoen please help me? do i have to declare the variable in here or is it passed by the facebook return method?

  • Daniel Smith

    I was having problems getting library to work. It ended up being a known bug in the API having to do with the SSL certificate. If anyone else is having problems with the above code, give this a try first before spending hours looking for the problem.

    In the file libraries/fb_connect.php look for:
    $this->fb = new Facebook(array( …

    and add the following 2 lines so that is reads like this:

    $this->fb = new Facebook(array(
    ‘appId’ => $this->_api_key,
    ‘secret’ => $this->_secret_key,
    ‘cookie’ => true,
    ));
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;

    This is a temporary solution until the really issue is resolved. If you wish to follow this issue here is the ticket:
    https://github.com/facebook/php-sdk/issues/issue/99

  • Daniel Smith

    I was having problems getting library to work. It ended up being a known bug in the API having to do with the SSL certificate. If anyone else is having problems with the above code, give this a try first before spending hours looking for the problem.

    In the file libraries/fb_connect.php look for:
    $this->fb = new Facebook(array( …

    and add the following 2 lines so that is reads like this:

    $this->fb = new Facebook(array(
    ‘appId’ => $this->_api_key,
    ‘secret’ => $this->_secret_key,
    ‘cookie’ => true,
    ));
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
    Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;

    This is a temporary solution until the really issue is resolved. If you wish to follow this issue here is the ticket:
    https://github.com/facebook/php-sdk/issues/issue/99

  • http://www.brennanstudios.com Brennan McEachran

    Thanks for sharing that back. Hopefully it saves someone time :)

  • http://www.brennanstudios.com Brennan McEachran

    Thanks for sharing that back. Hopefully it saves someone time :)

  • amcc

    I too had this problem, I declared $data['uri_var'] and it fixed the issue, perhaps this is correct

  • amcc

    I too had this problem, I declared $data['uri_var'] and it fixed the issue, perhaps this is correct

  • Yoga Herawan

    good information… Thank you very much..

  • Yoga Herawan

    good information… Thank you very much..

  • http://blog.shian.tw/codeigniter-facebook-librarie.html CodeIgniter Facebook Librarie | ????

    [...] · shian · CodeIgniter No comments – Tags: CodeIgniter, Facebook-api, PHP ShareFacebook Connect librarie [...]

  • SMark

    Can get the library to work on localhost.. “Invalid API key specified”
    On a production server works fine.
    At the application settings Site URL I have “http://localhost/xpto/”. This should work on a local server!
    Any one had this problem?

  • SMark

    Can get the library to work on localhost.. “Invalid API key specified”
    On a production server works fine.
    At the application settings Site URL I have “http://localhost/xpto/”. This should work on a local server!
    Any one had this problem?

  • http://www.facebook.com/GlynnPhillips Glynn Phillips

    Hi amcc,

    Could you explain this in a bit more detail as to were you did this?

    I am having this same problem

    Thanks
    Glynn

  • http://www.facebook.com/GlynnPhillips Glynn Phillips

    Hi amcc,

    Could you explain this in a bit more detail as to were you did this?

    I am having this same problem

    Thanks
    Glynn

  • http://www.facebook.com/GlynnPhillips Glynn Phillips

    Im just getting a blank page, Should I be seeing a connect button? because I cant see in the code were it would come in from and how would I pull this in so users can register using their facebook info?

  • http://www.facebook.com/GlynnPhillips Glynn Phillips

    I am recieving a similar error to one posted before can any one shed some light on this please?

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined variable: uri_var

    Filename: views/login_view.php

    Line Number: 47

    http://ridden.glynnphillips.co.uk/index.php/login/validate_user/” method=”post”>
    username:

    Fatal error: Call to undefined function form_input() in /home4/glynnphi/public_html/ridden/system/application/views/login_view.php on line 48

    Thanks
    Glynn

  • Abbdullah1

    fantastic lesson..
    but my question is, how to control facebook permission?

  • Abbdullah1

    fantastic lesson..
    but my question is, how to control facebook permission?

  • http://www.zonanegonet.com Darwin

    Excelente me funciono a la perfección ( no al primer intento pero asi se aprende).

  • http://www.zonanegonet.com Darwin

    Excelente me funciono a la perfección ( no al primer intento pero asi se aprende).

  • http://www.facebook.com/johnsico John Sico

    In case anyone else has the same problem I did,
    Where the tutorial says:

    $config['facebook_api_key'] = ‘your_facebook_api_key’;

    You must actually enter your app ID, not your API key. Then it’s all gravy.

  • http://www.facebook.com/johnsico John Sico

    In case anyone else has the same problem I did,
    Where the tutorial says:

    $config['facebook_api_key'] = ‘your_facebook_api_key’;

    You must actually enter your app ID, not your API key. Then it’s all gravy.

  • Lee

    Its a var you would enter to return the user to its current page. Look in _facebook_validate() to see hows its used fairly simple.

  • Lee

    Its a var you would enter to return the user to its current page. Look in _facebook_validate() to see hows its used fairly simple.

  • jimtomas

    Having a lot of trouble with this, just getting a blank page.

  • jimtomas

    Having a lot of trouble with this, just getting a blank page.

  • jimtomas

    fixed, removed comma in line 21 so
    “‘appkey’ => $this->fb_connect->appkey, ” becomes
    ‘appkey’ => $this->fb_connect->appkey “

  • jimtomas

    fixed, removed comma in line 21 so
    “‘appkey’ => $this->fb_connect->appkey, ” becomes
    ‘appkey’ => $this->fb_connect->appkey “

  • decasoft

    Hello,

    Some tips to help out others and a question… I couldn’t make this work yet but found some fixes. One important thing that was not mentionned is that you might need to enable CURL and shorttags in your php.ini file.

    Finally, I’m using CI2.0 and I was getting some error with the Controler not being found so I changed login.php to be like this:

    class Login extends CI_Controller {

    function __construct() {
    parent::__construct();
    }

    I changed the view file and removed the CI form helper functions (for user_id, psw and submit) and replaced them with real HTML code. It was not working for me somehow.

    However, I still get the same error Shrinimann gets. I tried various things to set this variable but no luck… I don’t want to set this variable to dummy data as I obviously see it’s used in the URL…

    I do see the FB connect button and if I click on it, it prompts me to accept the connection. However, it fails after some delay…

    Error is: Fatal error: Call to a member function get_user_by_fb_uid() on a non-object

    I would be vvvveeeeerrrryyyy kind if some could post a working example?
    Thanks!

  • decasoft

    Hello,

    Some tips to help out others and a question… I couldn’t make this work yet but found some fixes. One important thing that was not mentionned is that you might need to enable CURL and shorttags in your php.ini file.

    Finally, I’m using CI2.0 and I was getting some error with the Controler not being found so I changed login.php to be like this:

    class Login extends CI_Controller {

    function __construct() {
    parent::__construct();
    }

    I changed the view file and removed the CI form helper functions (for user_id, psw and submit) and replaced them with real HTML code. It was not working for me somehow.

    However, I still get the same error Shrinimann gets. I tried various things to set this variable but no luck… I don’t want to set this variable to dummy data as I obviously see it’s used in the URL…

    I do see the FB connect button and if I click on it, it prompts me to accept the connection. However, it fails after some delay…

    Error is: Fatal error: Call to a member function get_user_by_fb_uid() on a non-object

    I would be vvvveeeeerrrryyyy kind if some could post a working example?
    Thanks!

  • http://twitter.com/antic antic

    What’s with the “0 = 0″ in your get_user_by_fb_uid? Any plan to put this on GitHub?

  • http://twitter.com/antic antic

    What’s with the “0 = 0″ in your get_user_by_fb_uid? Any plan to put this on GitHub?

  • http://www.facebook.com/people/Dong-Phuong-Hong/1303124442 Dong Phuong Hong

    Login by CYASOFT

  • http://www.facebook.com/people/Dong-Phuong-Hong/1303124442 Dong Phuong Hong

    Login by CYASOFT

  • http://twitter.com/tobyns Tobyn Sowden

    Thank you for this!

  • http://twitter.com/tobyns Tobyn Sowden

    Thank you for this!

  • http://www.facebook.com/people/Kennedy-Road/1435624644 Kennedy Road

    123

  • http://www.facebook.com/people/Kennedy-Road/1435624644 Kennedy Road

    123

  • DADE

    My page keeps refreshing after I launch my app. Why is that?

  • DADE

    My page keeps refreshing after I launch my app. Why is that?

  • Rojanjohnv

    I could not enter ” class FacebookApiException extends Exception { ” class .Before the class I could enter

  • Rojanjohnv

    I could not enter ” class FacebookApiException extends Exception { ” class .Before the class I could enter

  • Anonymous

    So basically you don’t need the form because fb:login-button takes you to that facebook form, right?
    In addition, why did you store the password in the db? the login should be done with facebook, and then once you retrieve the uid, you can get the rest of the info from your database, isn’t it correct?

  • Anonymous

    So basically you don’t need the form because fb:login-button takes you to that facebook form, right?
    In addition, why did you store the password in the db? the login should be done with facebook, and then once you retrieve the uid, you can get the rest of the info from your database, isn’t it correct?

  • http://www.mattsaul.com/blog/?p=60 The 541510 » Blog Archive » Code Igniter and Facebook Applications

    [...] tried a few Facebook Connect tutorials before getting this one to work.  It doesn’t use the new version of CodeIgniter but I’ve found that the [...]

  • Sonicswede

    Seems I finally got it working. Thanks a bunch, man. I ended up calling functions within DX auth that I am using for registration and had to tweak it a bit but working well now!

  • http://www.facebook.com/mohamedfasilpp Mohamed Fasil

    My facebook session is not getting set.
    if(!$this->fb_connect->fbSession) {from there it bounces back to the login after succesfully allowing the rights for the application.

  • Vsdsd

     $uri_var = $this->uri->segment(3);

    m getting  $uri_var blank…so after login it redirected to /message/index and shows”
    404 Page Not Found
    The page you requested was not found.
    “……V

  • Nicole88

    hi,

    do i really have to create table user? Coz I’ve downloaded your code and tested it and it work without me creating the table user. Also want to ask if this is a bug or error, coz it gives me a blank page (no error or anything) upon successful logged in via facebook it redirected me back to my site: mydomain.com/login/facebook (blank page). why is that?

    -Nicole

  • Pedro

    Sorry about my english. I want make a script that when I have a password and login, i posto it direct to FB and login the user to use graph… it s possible?

    Thanks

  • Rajanikantsaner

    Hi I download the code but it doesn’t work. click on facebook login button Popup open for login details after submit the details it redirect to same page doesn’t seem if facebook login or not. just same form is opened. and not save in db also. also what is the use of text boxes same functionality is done with the login button like facebook login button. plz reply

  • Thierry Faure

    it doesn’t work!

  • Rsganesh

    i’m getting a blank page. Could anyone help me
     

  • Anna Harris

    I am fresher in PHP web development. Thanks for sharing good information how to creating a Facebook Connect Codeigniter framework.

  • http://www.facebook.com/profile.php?id=48906914 Graham McCarthy

    Hey Guys! I just wanted to let you know that this posting is super out of date. I have a new one, working on the newest version of CI with the newest FB sdk. I’ll try to take some time in the next few weeks to post about it.

  • Rafal

    How old is this article? I need to write program that will download all posts from CocaCola for example. How can I do it? is is possible to write code do download all posts

  • Azam Alvi

    how to decide or find that what is my ‘appId’ and secret?

  • 123

    help me!

    Call to undefined method Facebook::getSession() in C:xampphtdocsadwords-landingapplibrariesfb_connect.php on line 44

  • HJ

    Hi,

    after login it calls facebook() method of Login controller but the fbsession object is blank

    $this->fb_connect->fbSession

    do anything regarding coockies need to set ? I know at below places cookie need to set true required. let me know if any one have the similar issue and found solution

    $this->fb = new Facebook(array(
    ‘appId’ => $this->_api_key,
    ‘secret’ => $this->_secret_key,
    ‘cookie’ => true,
    ));

    FB.init({appId: ”, status: true, cookie: true, xfbml: true});

    Regards

  • HJ

    Hi

    come to know the cookie is set with the fbsr_ prefix by facebook js api code
    but CI php facbook.php get cookie name uses fbs_ as prefix changed fbsr_ but still the issue …

    Regards