Login With Facebook Using CodeIgniter

Login With Facebook Using CodeIgniter

In this tutorial, we are going to explain how to create a Facebook login in the CodeIgniter framework using Facebook PHP SDK. Facebook login is simply an open authentication used to provide access to server data after authorizing a user through a third party.

Before you begin to integrate login with Facebook using CodeIgniter, we need to download the Facebook PHP SDK library and also need Facebook App ID and App Secret.

In this example, we are using the Facebook PHP SDK library in CodeIgniter, this library gives users permission to sign in with their existing Facebook accounts in the Codeigniter application. so we can get the user information from Facebook.

Create Facebook App

Now we need to app id facebook and App Secret for Facebook login. first, we have to create the Facebook app. so you can see the below steps.

  • First, log in with your Facebook account and Go to Facebook for Developers page https://developers.facebook.com/apps/
  • Click on the My apps menu at the top navigation bar and click on Create App link
    • select app types
    • Enter the App Display Name and App Contact Email.
    • Click on the Create App button.
  • In the right sidebar menu, navigate to Settings > Basic menu
    • Add App Domains and select the Category of your App.
    • Click the Save Changes.
  • In the right sidebar menu, navigate to the Add a Product
    • Select Facebook Login product.
    • select the web platform.
    • Enter the Site URL and Save.
  • In the right sidebar menu, navigate to the Facebook Login > Settings menu.
    • Add Valid OAuth Redirect URIs field
    • Click the Save Changes.
  • In the right sidebar menu, navigate to the Settings > Basic menu.
    • get App ID and App Secret

php_facebook_login

Database Table Creation

Codeigniter configuration

application/config/autoload.php
in this config/autoload.php file, we need to load the library (database and session) and helper(URL). so you can use the below code to load the Codeigniter library and Codeigniter helper.

facebook.php
In this file, we have to set configuration variables, so we must specify the App ID, the App secret, and redirect URLs according to the Facebook application credentials.

Facebook PHP SDK download for Codeigniter

first, we need to create “facebook-php-sdk” directory into the “application/third_party” directory and after go to this directory using the command prompt. download the Facebook PHP SDK library using the below command.

create facebook library for Codeigniter 3

application/libraries/Facebook.php
First, we must have to Include the autoload file provided by Facebook PHP SDK in this class library. after then you can easily add login with Facebook functionality using PHP SDK v5 to CodeIgniter application.

create controller in Codeigniter

application/controllers/Facebook_login.php
Go to the application/controllers directory and create a new “Facebook_login.php” file.

create model in codeigniter

application/models/Facebook_model.php
Go to the application/modelsdirectory and create a new “Facebook_model.php” file.

create view in codeigniter

application/views/facebook_login.php
Go to the application/views directory and create a new “facebook_login.php” file.

Read Also
Login with Facebook Account using PHP
Login With Google Account Using PHP

Download

Please follow and like us: