Return to Snippet

Revision: 59938
at October 10, 2012 20:39 by ginoplusio

Initial Code
// uses the PHP SDK. Download from
// from the facebook app page
define('YOUR_APP_SECRET', '49fd00ce6237WEEWEWEWEWEW2');
// new facebook object to interact with facebook
$facebook = new Facebook(array(
 'appId' => YOUR_APP_ID,
 'secret' => YOUR_APP_SECRET,
// if user is logged in on facebook and already gave permissions
// to your app, get his data:
$userId = $facebook->getUser();
 <style>body { text-align:center; font-size: 40px }</style>
if ($userId) {
 // already logged? show some data
 $userInfo = $facebook->api('/' + $userId);
echo "<p>YOU ARE: <strong>". $userInfo['name'] ."</strong><br/>";
 echo "Your birth date is: ".$userInfo['birthday']."</p>";
} else {
 // use javaascript api to open dialogue and perform
 // the facebook connect process by inserting the fb:login-button
 <div id="fb-root"></div>
 <fb:login-button scope='email,user_birthday'></fb:login-button>
 window.fbAsyncInit = function() {
 appId : <?=YOUR_APP_ID?>,
 status : true,
 cookie : true,
 xfbml : true,
 oauth : true,
FB.Event.subscribe('auth.login', function(response) {
 // ------------------------------------------------------
 // This is the callback if everything is ok
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); = id; js.async = true;
 js.src = "//";

Initial URL

Initial Description
I will show you how to crate an app for facebook to handle the facebook connect process on your web site.
Then I will show you the php code to perform the login on facebook and retrieve the informations you need for your site.
The last suggestion will point how to merge facebook users with your users.
Follow the link above to get the full tutoriall with text and images.

Initial Title
Facebook Connect Tutorial

Initial Tags
php, facebook

Initial Language