PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Saturday 2 August 2014

Login With Facebook in your website using PHP

No comments :
We always seek attention in social networking site as we are very used to publish everything and liked and shared by others.But if we are developer in website development then our clients must seek Facebook login in their site and also we do.



You will get facebook php sdk from following link:

https://github.com/facebook/facebook-php-sdk

Here is little code for login in facebook using php

<?php
require 'src/facebook.php';  // Include facebook SDK file
$facebook = new Facebook(array(
  'appId'  => 'XXXXXXXXXXXXXX',   // Facebook App ID
  'secret' => 'XXXXXXXXXXXXXX',  // Facebook App Secret
  'cookie' => true,   
));
$user = $facebook->getUser();
if ($user) {
  try {
    $user_profile = $facebook->api('/me');
          $fbid = $user_profile['id'];           // To Get Facebook ID
        $fbuname = $user_profile['username'];  // To Get Facebook Username
        $fbfullname = $user_profile['name'];    // To Get Facebook full name
  } catch (FacebookApiException $e) {
    error_log($e);
   $user = null;
  }
}
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl(array(
         'next' => 'http://ruchisanghvi.in/demo/logout.php',  // Logout URL full path
        ));
} else {
$loginUrl = $facebook->getLoginUrl(array(
        'scope'        => 'email', // Permissions to request from the user
        ));
}
?>




No comments :

Post a Comment