How to login user to my website using twitter
<p>i am using twitter login for my website which allows user to login to my website. I have read some post for on SO which recommends using openid, But i suppose twitter allows only Oauth login. If anyone of you have implemented twitter login on your website, would you share your code. I am using PHP and yes i don't want to use any third party tools like janrain etc. Some posts on twitter login on SO are  not specific.</p>

<pre><code>&lt;?php

/* register your own at http://twitter.com/oauth_clients */
define("TWITTER_CONSUMER_KEY","");
define("TWITTER_CONSUMER_SECRET","");

/* API URL's */
define("TWITTER_OAUTH_HOST","https://twitter.com");
define("TWITTER_REQUEST_TOKEN_URL",TWITTER_OAUTH_HOST."/oauth/request_token");
define("TWITTER_AUTHORIZE_URL",TWITTER_OAUTH_HOST."/oauth/authorize");
define("TWITTER_ACCESS_TOKEN_URL",TWITTER_OAUTH_HOST."/oauth/access_token");
define("TWITTER_PUBLIC_TIMELINE_API",TWITTER_OAUTH_HOST."/statuses/public_timeline.json");
define("TWITTER_UPDATE_STATUS_API",TWITTER_OAUTH_HOST."/statuses/update.json");

define("TWITTER_UPDATE_PROFILE_BG_API", "http://api.twitter.com/1/account/update_profile_background_image.json");

define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));

?&gt;

&lt;?php

include("constants.php");

try {
    $oauth = new OAuth(TWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);

    /* Uncomment the line below to get lots of debug */
    //$oauth-&gt;enableDebug();

    $request_token_info = $oauth-&gt;getRequestToken(TWITTER_REQUEST_TOKEN_URL);

    printf("I think I got a valid request token, navigate your www client to:\n\n%s?oauth_token=%s\n\nOnce you finish authorizing, hit ENTER or INTERRUPT to exit\n\n", TWITTER_AUTHORIZE_URL, $request_token_info["oauth_token"]);

    $in = fopen("php://stdin", "r");
    fgets($in, 255);

    printf("Grabbing an access token...\n");

    /* grab the access token, which is your persistent token which you use for future requests */
    $oauth-&gt;setToken($request_token_info["oauth_token"],$request_token_info["oauth_token_secret"]);
    $access_token_info = $oauth-&gt;getAccessToken(TWITTER_ACCESS_TOKEN_URL);

    printf("Access token: %s\n",$access_token_info["oauth_token"]);
    printf("Access token secret: %s\n",$access_token_info["oauth_token_secret"]);

    printf("Fetching the public timeline JSON via %s\n",TWITTER_PUBLIC_TIMELINE_API);
    $oauth-&gt;setToken($access_token_info["oauth_token"],$access_token_info["oauth_token_secret"]);
    $oauth-&gt;fetch(TWITTER_PUBLIC_TIMELINE_API);

    /* from this point on OAuth is over, now handling the JSON response is in order */
    $json = json_decode($oauth-&gt;getLastResponse());
    printf("An item in the decoded JSON: %s\n",print_r($json[0],true));

} catch(OAuthException $E) {
    print_r($E);
}

?&gt;
</code></pre>
