2012-12-28 87 views
0

我正在嘗試使用PHP的CURL登錄到Vimeo.com,Vimeo login使用捲曲登錄到Vimeo

爲了提供CURL使用的數據(cookie和字段數據),我使用瀏覽器擴展從網頁中讀取字段數據並獲取cookie。然後我將這些數據傳遞給我的服務器,並嘗試使用curl登錄。

我相當肯定瀏覽器擴展部分工作正常(獲取正確的數據),因爲我可以驗證它傳遞的內容以及它應該傳遞的內容,並且它正確匹配。

此外,我也在其他網站上使用過它,並且登錄時沒有問題,但在vimeo上,exec將返回false

有什麼想法?

function curlpage(){ 
    $ch = curl_init(); 
    $url = $this->input->post('url'); 
    $data = $this->input->post('data'); 
    $cookie = $this->input->post('cookie'); 
    $method = $this->input->post('method'); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
    if(strtolower($method)=="put"){ 
     curl_setopt($ch, CURLOPT_PUT, 1); 
    } 
    else{ 
     curl_setopt($ch, CURLOPT_PUT, 0); 
    } 
    if(strtolower($method)=="get"){ 
     curl_setopt($ch, CURLOPT_HTTPGET, 1); 
    } 
    else{ 
     curl_setopt($ch, CURLOPT_HTTPGET, 0); 
    } 
    if(strtolower($method)=="post"){ 
     curl_setopt($ch, CURLOPT_POST, 1); 
    } 
    else{ 
     curl_setopt($ch, CURLOPT_POST, 0); 
    } 
    curl_setopt($ch, CURLOPT_FAILONERROR, true); 
    curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_CAINFO, getcwd().'/certificates/BuiltinObjectToken-EquifaxSecureCA.crt'); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_COOKIE, $cookie); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0"); 
    curl_setopt($ch, CURLOPT_REFERER, $url); 
    $error = curl_error($ch); 
    $url=curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
    if(!preg_match('/^http(s)?:\/\//', $url)){ 
     $url = 'http://' . $url; 
    } 
    $host = parse_url($url, PHP_URL_HOST); 
    $page = curl_exec($ch); 
    curl_close($ch); 
    return array('page'=>$page, 'url'=>$host, 'error'=>$error); 
} 

這裏是我送的上述功能我的服務器上的數據的樣本(用假電子郵件的密碼,並改變了餅乾):

 
data=action%253Dlogin%2526service%253Dvimeo%2526email%253Dhou%2540fah.com%2526password%253Dudwt%2526token%253D6b2fc081bcdf02b1f58a390d6a3f8b83 
cookie=__utma%3D18392654.1284111214.1456668252.1456678435.1456181183.3%3B__utmb%3D18302654.2.10.1454681883%3B__utmc%3D18232154%3B__utmz%3D17202654.1456675435.2.2.utmcsr%3Dgoogle%7Cutmccn%3D(organic)%7Cutmcmd%3Dorganic%7Cutmctr%3D(not%2520provided)%3B 
method=POST 
url=http%3A%2F%2Fvimeo.com%2Flog_in 
+0

我可以看到你在cookie中傳遞一個Token ..可以告訴你如何設法得到它? –

回答

0

Vimeo的,我居然發現成爲一個奇怪的網站案例。他們並沒有將所有的cookies設置在前面,而是設置了某些在提交表單時需要登錄的cookie。所以我的一個問題是我沒有提交所有正確的cookie信息。

我的第二個問題是我的數據在發送時沒有正確編碼。

所有的說法和我做的,我現在已經得到它的工作!

+0

你能告訴你如何解決這個問題的代碼,或者關閉這個問題嗎? – Popnoodles

1
$ret = customSendDataByCurl("https://vimeo.com/log_in"); 
preg_match("/xsrft: \'(.*)\',/i",$ret,$token); 
$token = $token[1]; 
echo "$token <hr>"; 

$cookie = '(copy from your browser using tamper data)... xsrft='.$token; 

$headers = array(
    "Referer: https://vimeo.com/log_in", 
    "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0", 
    "Accept: application/json", 
    "Accept-Language: en-US,en;q=0.5", 
    "X-Requested-With: XMLHttpRequest", 
    "X-Request: JSON", 
    "Content-Type: application/x-www-form-urlencoded; charset=utf-8", 
); 
$ret = customSendDataByCurl("https://vimeo.com/log_in?action=warm", "POSTDATA=email=(email url encoded)&token=".$token, $headers, $cookie); 


$fields = array(
    "action" => "login", 
    "service" => "vimeo", 
    "email" => "(email)", 
    "password" => "(pass)", 
    "token" => $token, 
); 
$headers = array(
    "Referer: https://vimeo.com/log_in", 
    "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0", 
    "Content-Type: application/x-www-form-urlencoded; charset=utf-8", 
); 
$ret = customSendDataByCurl("https://vimeo.com/log_in", http_build_query($fields), $headers, $cookie); 
$ret = customSendDataByCurl("https://vimeo.com/stats/video/84142281/totals/export:csv", http_build_query($fields), $headers, $cookie); 
var_export($ret); 

function customSendDataByCurl($agateway, $apostfields=null, $headers=array(), $cookie="") { 
    if(is_array($apostfields)) $apostfields = http_build_query($apostfields); 

    $cookiesFile = 'cookies.txt'; 

    $ch = curl_init($agateway); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_COOKIESESSION, true); 
    if ($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0'); 
    curl_setopt($ch,CURLOPT_COOKIEJAR,$cookiesFile); 
    curl_setopt($ch,CURLOPT_COOKIEFILE,$cookiesFile); 
    curl_setopt($ch, CURLOPT_COOKIE, $cookie); 
    if(!empty($apostfields)) curl_setopt($ch, CURLOPT_POSTFIELDS, $apostfields); 

    $response = curl_exec($ch); 

    if(!$response) $response="CURL #".curl_errno($ch).": ".curl_error($ch); 
    return $response; 
}