Home / PHP / Create Login with Facebook using PHP
untitled

Create Login with Facebook using PHP

Login with facebook: You can allow users to Login with facebook into your website. You don’t need to create an extra Signup page and management system. You can manage users from facebook app admin panel. Facebook login has great importance and it is easier for users to log into your website just with one click. In this tutorial, you will learn how to create login with Facebook using PHP.

Step 1: Create a Facebook App

  • Goto https://developers.facebook.com/apps and click add new app
  • Choose Website
  • Choose the name for your facebook app , enter your email address and choose the category and click Add new app
  • Select setting from sidebar add your website URL in Site URL form

Step 1: Create a login with facebook using php

Save App ID and App Secret in a safe place we will be using this in future.

Step 2: Create a Table in Database

Create a table (users ) in Database (Geekscage). In this table, we will have following columns  uid, oauth_id, oauth_provider, first_name, last_name, email, last_login. Execute this SQL Statements in the database you selected above to connect to the database.

Step 3: PHP

We are creating a class with name “User”,  This Function has one method “checkUserData“. This method takes user’s information and checks if User already exists in database then update user with newly provided information. Otherwise, we insert a new row for the user.

Login.php

fbConfig.php

index.php

logout.php

Conclusion:

In this tutorial, we have tried to create a login with facebook using PHP. This is a very basic tutorial in professional environment you might need more permissions from facebook Facebook Permissions Reference. If you have any suggestion or query feel free to post a comment.

Download Now

Share This:

About Hasnain