In our creeping tutorial, at alternately we will decide the folder technique of this project. After that you will dig in to the past how gave a pink slip you sew the Facebook apps and handle this app for Facebook login at your website. And easily we will discuss practically the blend style of our scripts. This tutorial helps you to draw whole process quicker and easier.
You boot check the lie demo of Facebook login by the whole of PHP from the before Demo equal and also efficient to reorganize the heart and soul in to project from the beyond the bounds Download
.
This duty has three folders suggested inc/ includes/ images/ and several PHP files. The folders and files process are supposing below:
inc/
base_facebook.php
facebook.php
includes/
functions.php
config.php
index.php
logout.php
images/
Facebook apps creation:
Go to the https://developers.facebook.com/apps/ and login at your Facebook developer account.
Create a dressy Facebook apps mutually your desired name savor Web Login.
If you please to show Facebook login at the localhost server, previously your App Domains should be localhost. Also localhost habitat will only field, heretofore you adopt platform. For acquire a platform be on the same wavelength on Settings connect from the progressive menu requirement at the apps gofer => gat along well on the Add Platform under size => propose Website piece of action => attain site URL (http://localhost/facebook_login_with_php/).
Now be on the same wavelength on Status & Review correlate from the progressive menu requirement and the way one sees it your apps as live. Contact electronic mail is prescribed for came up to snuff the apps reside option. If you have not append apps end email already, go to the settings boy friday and adopt email. Once you accord the make email, you would be suited to train the apps go on option.
Congratulation! your apps introduction has completed.
Database blue plate creation:
To five and dime shop the user reference, you prefer to construct a database and a table. At willingly create a database gat a charge out of "codexworld". After that imitate the small SQL search and stump the SQL sweat it out of on the database.
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `oauth_provider` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `oauth_uid` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `fname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `lname` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `gender` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `locale` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `picture` text COLLATE utf8_unicode_ci NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;Installation:
In this function you barely have to fine-tune only two files.
Database configuration (includes/functions.php):functions.php had the law on have Users class by the whole of some functions. Into the __construct() work we have configured the database and incorporate with the database. You require only to climax the $dbServer, $dbUsername, $dbPassword and $dbName variables worth with your MySQL server details.
function __construct(){
//database configuration
$dbServer = 'localhost'; //Define database server host
$dbUsername = 'root'; //Define database username
$dbPassword = ''; //Define database password
$dbName = 'codexworld'; //Define database name
//connect databse
$con = mysqli_connect($dbServer,$dbUsername,$dbPassword,$dbName);
if(mysqli_connect_errno()){
die("Failed to connect with MySQL: ".mysqli_connect_error());
}else{
$this->connect = $con;
}
}
Facebook API configuration (config.php): bring to light the config.php charge and fine-tune the $appId, $appSecret, $return_url and $homeurl variables value.
Note: You cut back find the App ID and App Secret from your Facebook Apps settings page.
<?phpinclude_once("inc/facebook.php"); //include facebook SDK
######### Facebook API Configuration ##########$appId = 'Insert Facebook App ID'; //Facebook App ID$appSecret = 'Insert Facebook App Secret'; // Facebook App Secret
$homeurl = 'http://localhost/facebook_login_with_php/'; //return to home$fbPermissions = 'email'; //Required facebook permissions
//Call Facebook API$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret));$fbuser = $facebook->getUser();?>
0 comments:
Post a Comment