Facebook Connect in Php

  |   API, PHP   |   2 Comments

Facebook Connect in PHP,Just Follow these Steps :-

Upload all the files of zip folder on server.(Attached with this post)

Step 1 : Just open the file where you have to use facebook connect.(e.g abc.php)

Step 2: Just include this javascript file in head :-

“<script src=”” type=”text/javascript”></script>”.

Step 3: Include the file “facebook.php”(Uploaded with this post).

Step 4: To put login button of facebook connect :-

<fb:login-button onlogin=’window.location=””;’ size=”medium” background=”white” ></fb:login-button>

Step 5: create the object :-

$facebook = new Facebook(‘Facebook API key’,’Facebook App Secret Key’,true);

Step 6: To get the user id of facebook login person:-

“$fUserId = $facebook->get_loggedin_user();”

Step 7: To get the session key for the api ->

$fc = new FacebookRestClient(‘facebook Api keyApi secret key’,$facebook->api_client->session_key);

Step 8: To initiate facebook connect,put this facebook connect–>

<script type=”text/javascript”>

var fb_api_key = “Facebook API key”;

if (fb_api_key>””) FB.init(“Facebook API key”, “/xd_receiver.htm”);


Step 9: To get user data of the login person –>

if($fUserId) {

$fUserData = $fc->users_getInfo($fUserId, ‘last_name,first_name,sex,current_location’);


Step 10: To see the fetched data :

<?php if($fUserId)



Firstname — <?php echo $fUserData[0][‘first_name’]; ?>

Lastname– <?php echo $fUserData[0][‘last_name’];?<

Sex– <?php echo $fUserData[0][‘sex’];?<

City– <?php echo $fUserData[0][‘current_location’][‘city’]; ?>

State–<?php echo $fUserData[0][‘current_location’][‘state’]; ?>

Country– <?php echo $fUserData[0][‘current_location’][‘country’]; ?>

Zip– <?php echo $fUserData[0][‘current_location’][‘zip’]; ?>

<?php } ?>

Step 11: To use the buttons(Login & Logout) if a person is login or not :

<?php if (!$fUserId) { ?>

<fb:login-button onlogin=’window.location=””;’ size=”medium” background=”white” ></fb:login-button>

<?php }

else {


<input type=”button” value=”Logout” onclick = ‘FB.Connect.logout(function() { document.location = “”; }); return false;’/>

<?php } ?>

Download : Facebook Files

It is done!

  • Lynn | Dec 15, 2016 at 6:53 am

    Oh yeah, falbuous stuff there you!

  • Buffy | Dec 15, 2016 at 10:24 am

    That’s an inuegions way of thinking about it.

Post A Comment

Things we have Done

Got an Idea ? Lets make it happen and Get a Free Quote of your website.Get a Free Quote