A few words of thanks would be greatly appreciated.

Add Facebook Connect to your website

This tutorial requires a sound knowledge in PHP and JavaScript as these APIs are quite difficult to use. This is a basic tutorial and may contain imperfections, thank for sharing your comments.
To access the Facebook APIs, you must register an application. Once registered, it will provide you with a secret key and an application ID that are essential to interact with.
Download PHP SDK
Upload to your server: /src/facebook.php
Facebook offers two ways to build your button: The XFBML method and other method. We will consider the second method, which is more flexible.

It's just a simple button to which we shall associate functions from the JavaScript SDK library.

This JavaScript code which brings together the required funtions:
<script type="text/javascript">    
function fblogout() {    
          FB.logout(function () {    
     window.location.reload(); });    
      window.fbAsyncInit = function() {    
          appId   : '<?php echo $facebook->getAppId(); ?>',    
          session : <?php echo json_encode($session); ?>,    
          status  : true,    
          cookie  : true,    
          xfbml   : true    

        FB.Event.subscribe('auth.login', function() {    

      (function() {    
        var e = document.createElement('script');    
        e.src = document.location.protocol + '//connect.facebook.net/fr_FR/all.js';    
        e.async = true;    
          //your fb login function    
          function fblogin() {    
     FB.login(function(response) {    
            }, {perms:'read_stream,publish_stream,offline_access'});    

To initiate connection, you call the fblogin() function during the onclick event.
To disconnect you can simply call fblogout().

fblogin() : verifies that the user is connected to facebook, if you are connected it will check that you have the necessary rights. Rights are customizable: perms:'read_stream,publish_stream,offline_access'
Learn more: http://developers.facebook.com/docs/authentication/permissions

fblogout(): This function will logoff the user from Facebook.
The following code will verify that the visitor is connected to Facebook and automatically record data to a table ($me), given that you have the necessary permissions. Note that you must write down your appid and your secret key and change the path to your facebook.php file.

require 'function/facebook/facebook.php';    
$facebook = new Facebook(array(  'appId'  => '',  'secret' => '',  'cookie' => true,));    
$session = $facebook->getSession();    
$me = null;    

 try {    
  $uid = $facebook->getUser();    
  $me = $facebook->api('/me');    
 catch(FacebookApiException $e){    

Note: if($session) is used to test the presence of Facebook session and if($me) to see if you have the user data

So once the data is retrieved, you will need to use then on your website:
If you have a custom registration and login system, this data can be used to intiate connection to a particular accoun
Learn more: User Registration Flows

__ To be completed __


A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Add Facebook Connect to your website », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).