Like Us on Facebook

How to login or signup with facebook API using PHP

Hi friends!! Today we are going to learn an interesting topic, that is how to login or signup with facebook API using PHP.  For every user communication website they must need a user login panel and for login they must need registration for proper authentication. Here comes beauty of social media like facebook, google plus, twitter for their signup process. And also users don’t have more time to fill all the information so they prefer social media login. So this tutorial will teach you how to signup or login with facebook using php.  

At first you have to login . Now you need to register facebook developer account. So click on register now button.

Here you have to accept facebook policy and click register. So you have successfully registered as a facebook developer. Now you can add facebook into your app or website.

Afetr login into your facebook developer account.Click Add a new app

Next you have to select area where you want to use this app, here I am using website.

Next click to the skip and create app id

Now you have to write display name and select category. Namespace is not necessary.  But remember that display name must be unique. Fill out this captcha.

Now your app has been created.

In this area you can see your app display name and you  get your appid and appsecret code. Actually  This dashboard is looking very complicated but you have to do very simple few steps here.Then give your contact information and click on add platform, select your area once again. Give your site URL and write your domain name inside app domains text box.

Now click on status and review on your left side bar, and turn on this app for make this visible to everyone.Your app is now live and you have implement on you website.


The script contains three folders called inc,includes and images with PHP files.

base_facebook.php // Class Get user Info

facebook.php // Class Get user Info

config.php // Configuration file

functions.php // Database Connectivity


// Main index file show data

logout.php // Destroy Your Session



$appId = ''; 
$appSecret = '';
$homeurl = 'http://localhost/facebook_login/'; 
$fbPermissions = 'email';

//Call Facebook API
          $facebook = new Facebook(array(
           'appId'  =>
          'secret' =>

$fbuser = $facebook->getUser();


Create Table users


// Database Connectivity, Insert and Update Code Here.




//destroy facebook session if user clicks reset
$fbuser = null;
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
$output = '<a href="'.$loginUrl.'"><img src="images/fb_login.png"></a>';     
$user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
$user = new Users();
$user_data = $user->checkUser('facebook',$user_profile['id'],$user_profile['first_name'],$user_profile['last_name'],$user_profile['email'],$user_profile['gender'],$user_profile['locale'],$user_profile['picture']['data']['url']);

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Login with Facebook using PHP by CodexWorld</title>
            <style type="text/css">
            h1{font-family:Arial, Helvetica, sans-serif;color:#999999;}

<?php echo $output; ?>






Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 0 )

    Leave a comment..

    Click to login.