How to Login with Facebook and Twitter

As we know Facebook and Twitter have become large in the social network world and both networks offering oAuth support. Nowadays web users not interested to filling the big registration forms. This tutorial helps you to avoid registration forms, It’s is very useful and simple to integrate.

Sample database users table columns id, email, oauth_uid, oauth_provider and username.

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 tutorial contains three folders called facebook,twitter and config with PHP files.
facebook //Facebook OAUTH library
twitter //Twitter OAUTH library
– functions.php
– dbconfig.php //Database connection
– fbconfig.php //Facebook API connection
– twconfig.php //Twitter API connection

Facebook Setup:
You have to create a application. Facebook will provide you app id and app secret id, just modify following code

define(‘APP_ID’, ‘Facebook APP ID’);
define(‘APP_SECRET’, ‘Facebook Secret ID’);

Twitter Setup:
Create a twitter application click here. Some like Facebook Twitter provide you consumer key amd consumer secret key using these modify following code.

define(‘YOUR_CONSUMER_KEY’, ‘Twitter Key’);
define(‘YOUR_CONSUMER_SECRET’, ‘Twitter Secret Key’);

Database configuration file.

define(‘DB_SERVER’, ‘localhost’);
define(‘DB_USERNAME’, ‘User Name’);
define(‘DB_PASSWORD’, ‘Password’);
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());

In root directory find out the below line at login-twitter.php code and replace yourwebsite.
$request_token = $twitteroauth->getRequestToken(‘http://yourwebsite.com/getTwitterData.php’);

If you want to modify your web project existing login or index pages, just use following code.

if (isset($_SESSION['id'])) {
// Redirection to login page twitter or 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=twitter”>Twitter_Login</a>
<a href=“?login&oauth_provider=facebook”>Facebook_Login</a>

Related Posts

20 thoughts on “How to Login with Facebook and Twitter

  1. Rolland

    Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a bit, but instead of that, this is great blog. A fantastic read. I will definitely be back.

  2. Rosetta

    Hi there! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a outstanding job!

  3. Nicole

    I know this if off topic but I’m looking into starting my own blog and was wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet savvy so I’m not 100% positive. Any suggestions or advice would be greatly appreciated. Thank you

  4. Viral Facebook App Blackhat

    Hello there, You may have conducted a wonderful career. Let me absolutely digg this as well as privately advocate for you to my pals. I’m positive are going to benefited from this website.

  5. Facebook App Ideas 2012

    Its such as you go through my head! Material realize considerably relating to this, just like you composed the actual guideline within it or something. I’m sure which you simply can do with several Percent so that you can electricity the solution property a little, although apart from that, that is great blog site. A superb study. I most certainly will undoubtedly be back.

  6. Christel

    Good day! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us beneficial information to work on. You have done a wonderful job!

  7. cheat drag racing ios

    I am no longer certain the place you are getting your info, but great topic. I needs to spend some time learning more or understanding more. Thank you for excellent info I used to be in search of this info for my mission.

  8. Arlie

    I was recommended this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my problem. You’re amazing! Thanks!

  9. Infographiste à toulouse

    This is very fascinating, You’re an excessively skilled blogger. I have joined your feed and stay up for seeking extra of your excellent post. Additionally, I’ve shared your web site in my social networks

  10. french montana ft the weeknd gifted

    I do accept as true with all the ideas you have introduced to your post. They are really convincing and can certainly work. Nonetheless, the posts are very quick for beginners. May you please lengthen them a bit from subsequent time? Thanks for the post.

  11. Deutsches Blackhat Forum

    I do believe all the concepts you’ve presented to your post. They are very convincing and will certainly work. Still, the posts are very brief for starters. May you please extend them a little from next time? Thanks for the post.

  12. Day Trading

    Superb website. Plenty of helpful info the following. We’re giving it to a few pals ans furthermore discussing in delectable. And obviously, thanks for your energy!

  13. бриллианты украшения

    I used to be suggested this blog through my cousin. I’m no longer positive whether this submit is written via him as no one else know such precise approximately my difficulty. You are wonderful! Thank you!

  14. Designer toulouse

    It does not take ideal time to have a number of programs for that long term which is time for it to be happy. We have check out this post and when I could I have to recommend people handful of interesting elements and also information. You may can create next reports with this content. I’m going to study even more factors roughly them!

  15. lira

    Woah this weblog is excellent i like reading your articles. Stay up the great paintings! You recognize, a lot of individuals are searching around for this info, you could aid them greatly.

  16. Facebook Jimbonz

    Pretty component of content. I simply stumbled upon your site and in accession capital to claim that I get actually loved account your blog posts. Anyway I will be subscribing in your feeds or even I achievement you access constantly rapidly.

  17. Versicherung Markt

    Enjoy it. I am interested in this data. Amazing information and facts I most certainly will visit to get specifics of diets.

  18. www.youtube.com

    We’ve been a variety of volunteers and beginning a fresh design in your neighborhood. Your site offered you having handy details in order to paintings on. You’ve conducted the good employment and also your whole area could be pleased to you personally.

  19. Fadness

    Good article. I had been verifying constantly this kind of weblog and i’m astounded! Very useful information particularly the ultimate part 🙂 My spouse and i care for these kinds of info lots. I used to be looking for this particular particular details for the period of time. Many thanks in addition to all the best ..

  20. How To Make Your Facebook App Viral

    Many thanks any other superb document. The spot more might just anybody obtain that sort of details in this an easy way associated with creating? I own a display a few weeks, that i’m with the search for such information and facts.


Leave a Reply

Your email address will not be published. Required fields are marked *