Login with facebook


Now a days most of the project required login through social media. This article will guide you to create login/ register with Facebook.

You need to generate your Application key and Application Secret. Most important your website must be HTTPS enabled. The redirect URL must be HTTPS:// otherwise it will not work and you will get Error message.

Click here to know more about Permissions in Facebook.
Click here to generate App ID/API Key and App Secret for Facebook.

Save the App Client ID and Client Secret and Redirect URL in fbconfig.php file.

fbconfig.php

require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
//FacebookSession::setDefaultApplication( 'Your APP ID','Your APP Secret' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('Your Redirect URL');

If the user registered before then our system will redirect the user to my account page otherwise it will ask the user to register for the first time.

/*Check if the user connected before */
$sql = db_query("select * from register_facebook where passcode='".$fbid."'");
$numrow = mysqli_num_rows($sql);
if($numrow > 0){
	$_SESSION['email'] 		= $femail;
	$_SESSION['passcode'] 	= $fbid;
	
	header('Location:myaccount.php');
	exit();
}else{
	$_SESSION['FBID'] = $fbid;           
	$_SESSION['USERNAME'] = $fbuname;
	$_SESSION['FULLNAME'] = $fbfullname;
	$_SESSION['EMAIL'] =  $femail;
	header('Location:index.php?success');
}
The MySql table used in this project
CREATE TABLE IF NOT EXISTS `register_facebook` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(50) DEFAULT NULL,
  `lastname` varchar(50) DEFAULT NULL,
  `email` varchar(60) DEFAULT NULL,
  `gender` varchar(10) DEFAULT NULL,
  `passcode` varchar(100) DEFAULT NULL,
  `profilepic` varchar(250) DEFAULT NULL,
  `loginwith` varchar(10) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 

Other Login/ Registration Systemss

Login/ Register With Twitter
Login/ Register With Linked In
Login/ Register With Yahoo!
Login/ Register With Gmail
Login/ Register With Hotmail
Login/ Register With Email



Demo   Pay $2.49 & Download File





Top