Tricks: Blogger: How to Login with Facebook and Twitter



How to Login with Facebook and TwitterFacebook and Twitter have become large in the social network world and both networks offering oAuth support. We developed a system for login with Facebook and Twitter. Today internet users not interested to filling the large enrollment forms. This script gives you the capacity to avoid enrollment forms, It Is is easy and really useful to incorporate.

Twitter and Facebook have grown to be big in both networks offering oAuth and the social network world support. If all they must do is login using their present Facebook account visitors will likely be a lot more inclined to become members and participate in your web site.
Login with Facebook and Twitter
It uses OAuth and workflow and the authority URL differs somewhat as described below, although the flow is quite similar.

Login with Facebook and Twitter

Please follow below steps to learn and add Login with Facebook and Twitter on your websites easily:

1. Database

Create new database with 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) );

2. Twitter Setup

Create Twitter application from twitter website and replace Twitter Key & Twitter Secret Key in twconfig.php file as shown below code.
<?phpdefine('YOUR_CONSUMER_KEY', 'Twitter Key');define('YOUR_CONSUMER_SECRET', 'Twitter Secret Key');?>

3. Facebook Setup

Create Facebook application from facebook website and replace Facebook APP ID & Facebook Secret ID in fbconfig.php file as shown below code.
<?phpdefine('APP_ID', 'Facebook APP ID');define('APP_SECRET', 'Facebook Secret ID');?>

4. Databas Configuration

Add your database details in dbconfig.php file as shown below code:
<?phpdefine('DB_SERVER', 'localhost');define('DB_USERNAME', 'username');define('DB_PASSWORD', 'password');define('DB_DATABASE', 'database');$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);?>

5. Twitter Login Config

In your root directory you can see login-twitter.php. Edit this file and replace yourwebsite.com to your main domain name.
$request_token = $twitteroauth->getRequestToken('http://yourwebsite.com/getTwitterData.php');

6. Index Page Config

If you want to add your own index page than you can change your index page with adding below codes in your index page.
<?phpsession_start();if (isset($_SESSION['id'])) {// Redirection to login page twitter or facebookheader("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=twitter">Twitter_Login</a><a href="?login&oauth_provider=facebook">Facebook_Login</a>
Click below button for  download full code script and extract to edit code to edit on your website for login with facebook and twitter.
facebook and twitter login

Comments