Hi Guys, we have already shared scripts on Login with Google Plus in your website using PHP. Many users requested to write similar example for twitter, so here is working script for login with Twitter using PHP. Its really useful when you want to avoid long signup forms for your users and let them login with existing popular social media account. This script is easy and ready to use, you need to just edit three lines in the script and you are all done.
Live Demo  Â
 [sociallocker]DOWNLOAD[/sociallocker]
First you need to create a twitter app from https://apps.twitter.com/app/new , here you need to enter App Name, Description, Website, Callback URL. Callback URL is the file path where twitter API would redirect after successful authentication.
After creating App in twitter you would get Consumer key (API key) and Consumer secret (API secret) these API key and API secret would be used in our code to authenticate.
Now lets go through all the files and important code, first we have index.php where you will have to place your consumer key and secret. Below is the block of code you need to edit:
/* Load required lib files. */ require_once('oauth/twitteroauth.php'); session_start(); class StripeAPI{ protected $consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; protected $consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; protected $oauth_callback = 'http://yoursite.com/twitter/callback.php'; function __construct() { if(empty($_SESSION['status'])){ $this->login_twitter(); } }
You can add consumer key, consumer secret and callback URL. Then we have callback.php which takes the request back from twitter after successful authentication. We also have destroy.php to clear the session and log user out of twitter.
That’s it, now you should have a working login with Twitter functionality in your website. It was quick in easy 😀 In next part we will save users information in database so that we can use it for other purposes. Share this easy tutorial with your friends and followers.
Hello dear can we have a tutorial on facebook login as well? we all like these both:)