2011-11-26 64 views
7

服務器成功接收登錄名,密碼和CAPTCHA。我如何使用cookie做到這一點?如何使用POST和Cookie使用cURL登錄

我不知道需要什麼信息的幫助我會告訴所有:

登錄表單:

<div id="loginForm"> 
<div id="logo"><img src="logo.png" border="0" /></div> 
<div class="loginBar">Login</div> 
    <form action="index.php" method="post"> 
    <input type="hidden" name="p" value="login" /> 
    <div class="line"> 
     <label>Captcha</label> 
     <img src="captcha/securimage_show.php" border="0" /> 
    </div> 
    <div class="line"> 
     <label>&nbsp;</label> 
     <input type="text" name="captcha" value=""/>     
    </div> 
    <div class="line"> 
     <label>&nbsp;</label> 
     <input type="submit" value="Login" /> 
    </div> 
    </form>       
<hr/> 
<a href="index.php?p=register" class="register" title="Click to register">Register</a> 
</div> 

捲曲代碼:

extract($_POST); 

    //set POST variables 
    $proxy = '127.0.0.1:8118'; 
    $url = 'http://example.com/index.php'; 
    $fields_string= 'p=login&user=' . $user . '&pass=' . $passwd . '&captcha=' . $_POST['captcha'] . '&submit=Login'; 

     //open connection 
     $ch = curl_init(); 

     //set the url, number of POST vars, POST data 
     curl_setopt($ch,CURLOPT_URL, $url); 
     curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 
     curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
     curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch,CURLOPT_PROXY, $proxy); 
     curl_setopt($ch,CURLOPT_COOKIEJAR, "cookie.txt"); 
     curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt"); 
    //curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
     //execute post 
     $result = curl_exec($ch); 

     print_r(curl_error($ch)); 
     print_r(curl_getinfo($ch)); 
     print_r(curl_errno($ch)); 

     //close connection 
     curl_close($ch); 

捲曲程序getinfo:

[url] => http://example.com/index.php 
[content_type] => text/html 
[http_code] => 200 
[header_size] => 415 
[request_size] => 325 
[filetime] => -1 
[ssl_verify_result] => 0 
[redirect_count] => 0 
[total_time] => 1.549389 
[namelookup_time] => 3.7E-5 
[connect_time] => 0.000138 
[pretransfer_time] => 0.000142 
[size_upload] => 62 
[size_download] => 1585 
[speed_download] => 1022 
[speed_upload] => 40 
[download_content_length] => 1585 
[upload_content_length] => 0 
[starttransfer_time] => 1.27051 
[redirect_time] => 0 
[certinfo] => Array () 
[redirect_url] => 

真正的cookie:

Host:     example.com 
Name:     PHPSESSID 
Path:    /
Content:    7qk7bb17nr030g5j59h2gq3nq6 
Content raw:   7qk7bb17nr030g5j59h2gq3nq6 
Expires:    At end of session 
Expires raw:   0 
Send for:    Any type of connection 
Send for raw:   false 
Created:    Fri 25 Nov 2011 10:37:24 PM EET 
Created raw:   1322253443569272 
Last accessed:  Sat 26 Nov 2011 11:06:02 AM EET 
Last accessed raw: 1322298361723991 
HTTP only:   No 
HTTP only raw:  false 
This domain only:  No 
This domain only raw: false 
Policy:    no information available 
Policy raw:   0 
Status:    no information available 
Status raw:   0 
--- 

Gerenated文件通過的libcurl在cookie.txt:

# Netscape HTTP Cookie File 
# http://curl.haxx.se/rfc/cookie_spec.html 
# This file was generated by libcurl! Edit at your own risk. 

example.com FALSE / FALSE 0 PHPSESSID crs9cm100agdfsujsncr964jg7 

當我運行這段代碼,賬戶,passwd和驗證碼全成由服務器接收,但有錯誤與餅乾:

確保你已啓用Cookie

另外我看到了真正的Cookie Con帳篷原料與libcurl生成的不同。

另外我看到,從我的表單我成功抓住了網絡服務器cookie。

PS !!我收到的cookie從這個鏈接登錄表單:

<img src="captcha/securimage_show.php" border="0" /> 
+0

與今天早些時候詢問的問題不完全相同嗎?看起來原來的問題已被刪除。只是想知道它發生了什麼,因爲它顯然是相同的確切問題和來源。 – davidethell

+0

沒有人迴應..我只是試圖找到一些提示(但也nosuccess – Tedy

+0

你有沒有嘗試只是發佈你的數據到目標網站直接,而不是使用CURL(IE瀏覽器,包裝形式標籤,並使目標爲目標URL「http://example.com/index.php」)? –

回答

0

這可能是缺少的屬性

curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); 

這樣捲曲將被迫忽視「老」會話cookie,並開始一個新的會話的原因代替。

+0

使用此參數也可以使用2個不同的cookie。 1.在cookie.txt中和2.真正的cookie。 – Tedy