Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

 1 Answer(s)

  • Priyanka, Facebook has its own SDK which allow user to login & signup via facebook

    Refrence URL: https://github.com/facebook/facebook-php-sdk-v4

    or you can use below code to integrate facebook login

    1. Paste JavaScript code in header or footer:

    The below code is a JavaScript code; this function will call when user click on login fb button.

    <script type="text/javascript">
    window.fbAsyncInit = function()
    {
        FB.init(
        {
            appId: 'set&#95;fb&#95;app&#95;Id', // App ID
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true, // parse XFBML
            oauth: true 
        });
    };
    
    function loginViaFacebook()
    {
        FB.login(function(response)
        {
            if (response.authResponse)
            {
                // connected
                window.location.href = 'http://example.com/fbuserlogin'; // set your redirect url after login
            }
            else
            {
                // User cancelled login or did not fully authorize
                location.reload(true);
            }
        },
        {
            scope: 'email,public&#95;profile'
            //https://developers.facebook.com/docs/facebook-login/permissions/v2.2
        }
        );
    }
    
    (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
    '//connect.facebook.net/en&#95;US/all.js';
    document.getElementById('fb-root').appendChild(e);
    }());
    </script>
    

    note: please replace &#95; with "_" while copying the above code.

    1. Use below html code to render facebook login button.
    2. < input type="button" value="Sign in with Facebook" onclick="javascript:loginViaFacebook();" /> < div id="fb-root">
    3. Please extract attached file & call it like this:- require_once('set_absolute_path/fb/src/facebook') then, use below PHP code to get user details after authentication from Facebook.
    4. // Set facebook app credential
              $facebook = new Facebook(array(
                  'appId'  => 'set_fb_app_Id',
                  'secret' => 'set_fb_secret'
              ));
      
              // Get User ID
              $user = $facebook->getUser();
      
              if ($user)
              {
                  try
                  {
                      // Proceed knowing you have a logged in user who's authenticated.
                      $user_profile = $facebook->api('/me');
      
                      // Get profile image
                      $profile_image = $facebook->api('me/picture', array('redirect'=>false, 'height'=>'125', 'type'=>'normal', 'width'=>'125'));
      
                      // Process your logic here
                  }
                  catch (FacebookApiException $e)
                  {
                      $user = null;
                  }
              }
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: