php - Curl: POSTs converting to GETs -
i designing simple twitter login script curl , when try execute it, login form sent when sending post. due header of user's homepage displayed in browser.
any input appreciated.
<?php function tw_connect($user, $pwd) { $agent = "mozilla/5.0 (windows; u; windows nt 5.2; en-us; rv:1.9.2.16) gecko/20110319 firefox/3.6.16"; $ch = curl_init('http://www.twitter.com'); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_returntransfer, true); $c = curl_exec($ch); curl_close($ch); preg_match_all('#authenticity_token" type="hidden" value="(.*)"#u', $c, $g); $g = $g[1][0]; $post = 'authenticity_token=' . trim($g[1]) . '&authenticity_token=' . trim($g[1]) . '&return_to_ssl=false&redirect_after_login=&session' . urlencode("[username_or_email]") . '=' . $user . '&' . urlencode("session[password]") . '=' . $pwd . '&commit=' . urlencode("sign in"); $ch2 = curl_init('https://twitter.com/sessions'); curl_setopt($ch2, curlopt_useragent, $agent); curl_setopt($ch2, curlopt_referer, 'http://twitter.com/'); curl_setopt($ch2, curlopt_post, true); curl_setopt($ch2, curlopt_postfields, $post); curl_setopt($ch2, curlopt_cookiefile, 'cookie.txt'); curl_setopt($ch2, curlopt_cookiejar, 'cookie.txt'); curl_setopt($ch2, curlopt_followlocation, true); curl_setopt($ch2, curlopt_httpheader, array('expect:')); curl_setopt($ch2, curlopt_cookiesession, true); curl_setopt($ch2, curlopt_ssl_verifypeer, false); curl_setopt($ch2, curlopt_returntransfer, true); $v = curl_exec($ch2); echo $v; } tw_connect('username','password'); ?>
i think problem this:
curl_setopt($ch2, curlopt_followlocation, true); when redirecting through location header, post dropped , request turned get. i'm not sure if it's necessary here or not.
Comments
Post a Comment