How to set up Login with facebook tutorial
Database set up file
Database users table columns id, email, oauth_uid, oauth_provider and username.
CREATE TABLE users
(
id INT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(70),
oauth_uid VARCHAR(200),
oauth_provider VARCHAR(200),
username VARCHAR(100),
twitter_oauth_token VARCHAR(200),
twitter_oauth_token_secret VARCHAR(200)
);
The a folders called facebook and config with PHP files.
index.php
home.phplogin-facebook.php
Setup Facebook
You have to create a application. Facebook will provide you app id and app secret id, just modify following code .
fcconfig.php
<?php
define('APP_ID', 'Facebook APP ID');define('APP_SECRET', 'Facebook Secret ID');
?>
databaseconfig.php
An Database configuration file.
<?php
define('DB_SERVER', 'localhost');define('DB_USERNAME', 'User Name');
define('DB_PASSWORD', 'Password');
define('DB_DATABASE', 'DATABASE');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) ordie(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>
index.php
If you want to modify your web project existing login or index pages, just use following code.
If you want to modify your web project existing login or index pages, just use following code.
<?php
session_start();if (isset($_SESSION['id'])) {
// Redirection to login page facebook
header("location: home.php");
}
if (array_key_exists("login", $_GET))
{
$oauth_provider = $_GET['oauth_provider'];
if ($oauth_provider == 'twitter')
{
header("Location: login-twitter.php");
}
else if ($oauth_provider == 'facebook')
{
header("Location: login-facebook.php");
}
}
?>
//HTML Code
<a href="?login&oauth_provider=facebook">Facebook_Login</a>
For any Query and Suggestion feel free to comment below to make our service better
Thanks and Best regards
Amit Sharma