This is a short tutorial to implement login with facebook in FudForum

First of all, you need a Facebook application id, so you have to go to:

create your facebook application and get the application id to be used in your forum


then, you need to modify a couple of files in your template:



you have to add a script, provided by facebook (the script will contain you app id) 

window.fbAsyncInit = function() {
  appId : '<your app id>',
  cookie : true,
  xfbml : true,
  version : 'v7.0'
(function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); = id;
  js.src = "";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function checkLoginState() {
  FB.getLoginStatus(function(response) {
  if(response.status == "connected") {

add an hidden field in login form:

    <input type="hidden" name="fbtoken" />

(this field is populated by script)

and the login with Facebook button :

<div class="fb-login-button" data-size="large" data-button-type="login_with" data-layout="default"
data-auto-logout-link="false" data-use-continue-as="false" data-width=""
role="button" class="btn btn-primary"




this is the file where we will process the login form with new file fbtoken, posted by the script:

in this file, we will add the following piece of code:


// login with facebook
if (!$usr_d && (isset($_POST['fbtoken']) && $_POST['fbtoken']!="")) {
   $url = ",name,email&access_token=".$_POST['fbtoken'];

   //Make the API call
    if ($result = @file_get_contents($url)) {

      //Decode the JSON.
      $decoded = json_decode($result, true);

      if (isset($decoded['error'])) {
         login_php_set_err('facebook', $decoded['error']['message']);
      } else {

         $login = $decoded["name"];
         $fbid = $decoded["id"];
         $email = $decoded["email"];

         if (!($usr_d = db_sab('SELECT last_login, id, passwd, salt, login, email, users_opt, ban_expiry, ban_reason FROM {SQL_TABLE_PREFIX}users WHERE email='. _esc($email)))) {
              /* Cannot login: user not in DB. */
              $GLOBALS['_ERROR_'] = 1;
              login_php_set_err('login', 'Email not found, please register');
         } else {
              // provided dat will be checked by standard fudforum login code


you can find a fully working example here: