Authenticate Users With Their Facebook Account
Jun 14th, 2011A good and easy way to deal with Facebook authentication is to implement the server side flow with the Facebook PHP SDK (see on github). Here is how you do that :
After that, if $user
is not null
, it means that the user is
authenticated. So here is what you can display on your page :
<?php if ($user): ?>
<a href="<?php echo $facebook->getLogoutUrl() ?>">
Logout of Facebook
</a>
<?php else: ?>
<a href="<?php echo $facebook->getLoginUrl() ?>">
Login with Facebook
</a>
<?php endif ?>
When the user is authenticated, you can make API calls with his access
token (stored in $facebook
) :
For the complete flow, you can see the example of the Facebook PHP SDK which is well documented.