<? ob_start(); session_start();
# First call gets hidden form field authenticity_token
# and session cookie
$ch = curl_init();
$sTarget = "http://ttanaliz.com/oauth.php";
$veri = file_get_contents($sTarget);
preg_match('@<input id="oauth_token" name="oauth_token" type="hidden" value="(.*?)"@si',$veri,$baslik);
echo $redirect = $baslik[1];
$sTarget = "https://api.twitter.com/oauth/authenticate?oauth_token=".$redirect."";

curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
# curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_REFERER, "CURLOPT_REFERER");


$html = curl_exec($ch);

# parse authenticity_token out of html response
preg_match('/<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token"\/>/', $html, $match);
$authenticity_token = $match[1];



$username = "Yasam_Saglik";
$password = "123serkan";

# set post data
$sPost = "session[username_or_email]=$username&session[password]=$password";

# second call is a post and performs login


curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded")); 

# display server response
curl_exec($ch);
curl_close($ch);

?>