Login with Facebook using PHP

PHP Facebook Graph API allows users to login in a web application with Facebook credentials. In this tutorial, you will learn how to build a Login with Facebook Account using PHP. This is a very simple example, you can just copy-paste, and change according to your requirement.
Before starting to implement the Login with Facebook using PHP, look files structure:
  • login-facebook
    • css
    • templates
    • vendor
    • config.php
    • index.php
    • profile.php
    • menus.php.php
Step 1: Login to Facebook Developers
Go to the Facebook Developers Apps and Log In with your Facebook ID.
Step 2: Create an App
Click on the Create App button
Step 3 – Advanced Setting
Goto Setting >> Advanced and add redirect URL:
Step 4 – Add valid auth URL
Add valid auth redirect URL. So, click Facebook Login >> Setting and add valid auth redirect URL:
Step 5: get app key and secret key
Finally, get app key and secret key Setting >> Basic
Install the Facebook PHP SDK Library
Install it using Composer
Step 6: Create Config file
Create file named config.php In this file, we will put the facebook app key and secret key
Step 7: Create file index.php
Create an index.php file. In this PHP file we will show the facebook login.
Step 8: Create a profile.php
Create a profile.php file. In this file, we will show logged in user information like name, email, profile image and more.
Create files named (header.php and footer.php)
This file contains the header and footer section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header and footer section.
header.php
menus.php
footer.php