How to Login with Facebook in CodeIgniter

Integrate Facebook login is the most used feature for today’s web application. Login with Facebook feature helps users to log into the web application easily. In this tutorial, we’re going to explain how to integrate Facebook login in CodeIgniter using Facebook PHP SDK with Facebook Graph API.

Before you begin to integrate Login with Facebook in CodeIgniter, check below steps

Click here to download and Click here to demo

Step 1: Config (application/config/autoload.php)

$autoload['libraries'] = array('database','email','session');
$autoload['helper'] = array('url', 'file');

Step 2: Config (application/config/facebook.php)

$config['facebook_app_id']              = '';
$config['facebook_app_secret']          = '';
$config['facebook_login_type']          = 'web';
$config['facebook_login_redirect_url']  = 'login';
$config['facebook_logout_redirect_url'] = 'login/logout';
$config['facebook_permissions']         = array('email');
$config['facebook_graph_version']       = 'v2.6';
$config['facebook_auth_on_load']        = TRUE;

Step 3: application/libraries/Facebook.php

Facebook App and API configuration variables are defined in this file.

Step 4: Load Facebook libraries in __construct function

function __construct() {

Step 5: Facebook Account button on click and redirect controller function like (index())

public function index(){
	$userData = array();
		$userProfile = $this->facebook->request('get', '/me?fields=id,first_name,last_name,email,gender,locale,picture');
		echo "<pre>";
		$data['authUrl'] =  $this->facebook->login_url();

Step 6: Facebook Account Response Output

    [id] => 1455845184510060dsfsd
    [first_name] => Hardik
    [last_name] => Dayani
    [email] =>
    [gender] => male
    [locale] => en_GB
    [picture] => Array
            [data] => Array
                    [is_silhouette] => 
                    [url] =>



Step 7: Logout Controller Function

public function logout() {

Leave a Reply

Your email address will not be published. Required fields are marked *