Download libraries from https://github.com/abraham/twitteroauth

Then use following code for connecting with Twitter. The code will provide you a URL, clicking on that URL it takes you to the Twitter login window. Once you provide your login credentials and allow the access to the application, it lands you to the callback URL which you specified for your application.

<?php

require_once(‘twitteroauth.php’);
/* Application Details */

$connection = new TwitterOAuth(“—-Your Consumer Key —–“,
“————Consumer Secret————-“);

/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);

/* Save temporary credentials to session. */
$token = $request_token[‘oauth_token’];
$secret= $request_token[‘oauth_token_secret’];

 /* If last connection failed don’t display authorization link. */
switch ($connection->http_code)
{
case 200:
/* Build authorize URL and redirect user to Twitter. */
   $url = $connection->getAuthorizeURL($token);
   echo“<a href='”. $url.“‘>Login With Twitter </a>”;
   break;

default:
/* Show notification if something went wrong. */
   echo ‘Could not connect to Twitter. Refresh the page or try again later.’;
 }

?>