Read Time: 3 minutes

Users today avoid long registration forms as they feel it is time-consuming and require too many details from the users.

Many developers have worked on resolving the UX issue using the Facebook login through their applications. PHP Web Development companies are already using this alternative instead of the traditional login process.

Most websites have a general registration form for signing up on their websites but at the same time most users also want to skip this step. This is where you can allow your users to access your website using the Facebook Login feature.

This saves the users time as they are no more willing to fill in the large registration form to access the website content.

To get the latest version of Facebook SDK v5.x you will need to have the following configuration beforehand –

  • The PHP version must be greater than 5.4.
  • Mbstring extension should be enabled on your server.

Follow The Below Steps To Add A Facebook Login On Your Website

1.     Create Facebook Application

To get access to the Facebook API you need to create a Facebook app. This will give you an App ID and an App Secret which will be used while calling the Facebook API. Sign in to Facebook by going to Click on the Add New App button and select Website as your platform.

Enter the application name, Email ID, and select a relatable category for the application. Click on the Create App ID button which will create an application on Facebook. Now go to settings where you will find the App Secret and the App ID. Add the website URL in the App Domain and use the IDs in the PHP application.

Click on the Add Platform tab and enter the URL of the website again. Then you need to follow a few more steps which are as below –

  • Redirect to and log in using your Facebook Account.
  • Click on the My Apps menu and select the Create App link.
  • In the pop up, you have to define the App Display name details and select the Create App ID.
  • Now move to Setting > Basic link.
  • Here specify the App Domains, Terms of Service URL, Privacy Policy URL, and select Category. Then click on Save Changes.
  • Now go to Add a Product page and click on the plus button.
  • Navigate to the Add a Product page and in the pop up you have to select a website.
  • After selecting the website option, you will define your app Site URL.
  • Go to the dashboard link and Set up the Facebook Login product.
  • After you complete the Setup Facebook login product, a new web page will load where you have to define Valid OAuth Redirect URLs and save changes.

2.     Create the Application on Server

Visit the server and launch the SSH terminal and log in using the master credentials. Go into the application folder by running the below command:

$ cd applications/{your application folder}/private_html/

3.     Download the Facebook SDK

The recommended method of installing the libraries on the platform is the Composer. Create a composer file to install the Facebook SDK. In the SSH terminal run a composer in it’s command and add the required information to it. This will create a composer.json file in the application folder. Add the below code into the file:


“require”: {

“facebook/graph-sdk” : “~5.0”



Now run the composer install command to finalize the installation of the Facebook SDK.

4.     Initialize SDK and get User Information

It is time to initialize the Facebook SDK and get the access_token from Facebook. After the authentication of the token is done, user information is collected and is redirected to the profile page where user information is to be displayed. In the application folder, create two files namely Profile.php and Index.php.

You will need to hire PHP Developers to add the required code to the Index.php files which will display the Facebook button to log in. This button will help redirect the users to the Facebook login through which they can sign in to their account effortlessly.

Also, you will need to add the relevant code into the profile.php to display the retrieved information of the users. When you hire PHP Developers they will add the necessary code into this file which will help in presenting the information in a simple format.

After the user is authenticated with the Facebook account the following things will follow:

  • Facebook Graph API will be used to retrieve profile information.
  • The account data will be inserted into the database using the checkUser() function of the User class.
  • SESSION will store the user’s account information.
  • Profile details like First Name, Name, Last Name, Email, Picture, Profile Link, and Gender will be displayed on the webpage.
  • Use of the getLogoutUrl() method of login helper class will generate Logout link.

Conclusion On How To Add A Facebook Login To Your Website

In this blog, we have shown you the easiest method to add a Facebook login into the PHP website. PHP Web Development Company can help you in integrating the Facebook login effortlessly and improve the performance of the website. Facebook login makes your PHP website more user-friendly as it speeds up the registration process.

Never forget to secure the website as users are sharing their sensitive data with your platform.

Let us know if you prefer to log in to a website through the site’s own login or through the Facebook login…

Previous Post
LEAD GENERATION STRATEGIES: Ways To Generate More Leads And Sales
Next Post
The Best FACEBOOK AD Formats Worth Investing In for 2021

Related Posts

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x