The first thing you have to do of course to register your application in facebook. You can do that here.
When finished, you will be given an API Key and Application Secret codes, these codes will be use later in the connect API.
You can now write your php file like the sample below:
<?php
define('FACEBOOK_API_KEY', 'YOUR API KEY');
define('FACEBOOK_SECRET', 'YOUR SECRET KEY');
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
$fb_cookie = get_facebook_cookie(FACEBOOK_APP_KEY, FACEBOOK_SECRET);
if ($fb_cookie) { //if logged in
$user = json_decode(file_get_contents('https://graph.facebook.com/'.$fb_cookie['uid'].'?access_token='.$fb_cookie['access_token']));
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: "<?php echo FACEBOOK_APP_KEY; ?>", status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
document.location.href = 'document.location.href';
});
function fb_logout() {
FB.logout(function(response) {
document.location.href = 'document.location.href';
});
}
</script>
<?php if (!$fb_cookie) { //if not login ?>
<div>
<fb:login-button perms="publish_stream,user_photos" v="2"><fb:intl>Connect with Facebook</fb:intl></fb:login-button>
</div>
<?php } else { ?>
<div>
<div class="logout">
HI, <?php echo strtoupper(substr($user->first_name, 0, 17)); ?>! | <a href="javascript:fb_logout()">LOGOUT</a>
</div>
</div>
<?php } ?>
<!-- do your things here-->
</body>
</html>
There you go, simple application that has a connect button and logout button to sign out.
If you are using Jquery tools plugin, you cannot use the flashembed feature as it would give you error in Internet Explorer "your api key is not valid.... etc". That's the only issue that I found throughout my experience.
You can get more info at http://developers.facebook. com/docs/guides/web.