You can use the Facebook PHP SDK (see on github). So you will have something like :
require "facebook.php"; $facebook = new Facebook(array( 'appId' => YOUR_APP_ID, 'secret' => YOUR_APP_SECRET, )); $user = $facebook->getUser();
You then have to check if you have a valid access token by making an API call. If it does not raise any exception, then you have a valid access token :
if ($user) { try { $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { $user = null; } }
You need then to display the login or logout link :
<?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 ?>
All the info you ask for are stored in the the array $user_profile, you can trying a var_dump($user_profile) to see where they are.
you may want to check the example page of the Facebook PHP SDK which is well documented.
Hope that helps.