2012-04-03 174 views
0

我正在嘗試使用以下cURL操作登錄bangme.net圖片評級網站。當我檢查登錄表單時,這些ID是signin_UserName,signin_UserPass。名稱是簽名$用戶名,簽署$ UserPass。該腳本似乎沒有與下劃線一起工作,因爲結果導致我要求我登錄儘可能遠的頁面。我無法使用美元符號名稱,因爲它把它變成了一個變量。我注意到這個和類似腳本的一些示例顯示了一些以'&'標誌開頭的字段,當它們沒有在他們想要登錄的網頁的表單上。這是做什麼的?任何你可以提供的援助將不勝感激。謝謝。使用捲曲登錄

$username = "username"; 
$password = "password"; 
$url = "http://www.bangme.net/starform.aspx"; 
$cookie = "cookie.txt"; 

$postdata = "signin_UserName=" .$username . "signin_UserPass=" .$password; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_REFERER, $url); 

curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch); 

echo $result; 
curl_close($ch); 

新代碼:

$username = "username"; 
$password = "password"; 
$url = "http://www.bangme.net/signin.aspx"; 
$cookie = "cookie.txt"; 

$post = array(
     '__EVENTTARGET'=>"" , 
     '__EVENTARGUMENT'=>"", 
     '__VIEWSTATE'=>"/wEPDwUJMzQ0MjU1MjA0ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAwUJbGFzdHBob3RvBQh2b3RleWVzMgUHdm90ZW5vMgfkai25gOMuDdbmzYMWHA2LgYKt", 
     '__EVENTVALIDATION'=>"/wEWDgLmnpGMBwKOwMbqCwK4wb4IAv/10agEAqHH7a8KAtXfk+ULAt/Q94gCAvS2udYOAqrdhtcHAq+k5d0LAo+Au5MKApm/3+0OAqDCuuYMArCmgTeosqrEgmB3P5bavC40rTc6dbeF1g==", 
     'signin$UserName'=>$username , 
     'signin$UserPass'=>$password , 
     'signin$Button1.x'=>42, 
     'signin$Button1.y'=>17 
     ); 

$postData = http_build_query($post); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//changed from 0 to 1 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_REFERER, $url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//new 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//new 


curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
curl_setopt($ch, CURLOPT_POST, 1); 
$result = curl_exec($ch); 

echo $result; 
curl_close($ch); 

回答

2

我看到3件事錯在這裏

A.錯誤的變量聲明....

修正

$post = 'signin$UserName=' . $username . '&signin$UserPass=' . $password; 

B.錯誤的URL

糾錯

http://www.bangme.net/signin.aspx 

C.參數不完整的系統要求如下:

編輯1名

$post = array(
     '__EVENTTARGET'=>"" , 
     '__EVENTARGUMENT'=>"", 
     '__VIEWSTATE'=>'/wEPDwULLTEyMzUzNDExNjFkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYCBRdzaWduaW4kUmVtZW1iZXJDaGVja2JveAUOc2lnbmluJEJ1dHRvbjFA3HLFp6KEVYvii7p6PjecyYMsaw==', 
     '__EVENTVALIDATION'=>'/wEWBQL/xuPVDgLCoo75CQKoiOf4DQKtwMGFDgLz0rmTDUnuxoGtW34gNpQqIpwh3OT11JJl', 
     'signin$UserName'=>$username , 
     'signin$UserPass'=>$password , 
     'signin$Button1.x'=>42, 
     'signin$Button1.y'=>17 
     ); 
$postData = http_build_query($post); 

編輯2

完整標題...剛剛發現它也有餅乾

POST http://www.bangme.net/signin.aspx HTTP/1.1 
Host: www.bangme.net 
Connection: keep-alive 
Content-Length: 391 
Cache-Control: max-age=0 
Origin: http://www.bangme.net 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19 
Content-Type: application/x-www-form-urlencoded 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Referer: http://www.bangme.net/signin.aspx 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 
Cookie: ASP.NET_SessionId=1jqjwt45h0gpzb452rvrcu55; __utma=178887351.705741064.1333412926.1333412926.1333412926.1; __utmc=178887351; __utmz=178887351.1333412926.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmb=178887351 

__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTEyMzUzNDExNjFkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYCBRdzaWduaW4kUmVtZW1iZXJDaGVja2JveAUOc2lnbmluJEJ1dHRvbjFA3HLFp6KEVYvii7p6PjecyYMsaw%3D%3D&__EVENTVALIDATION=%2FwEWBQL%2FxuPVDgLCoo75CQKoiOf4DQKtwMGFDgLz0rmTDUnuxoGtW34gNpQqIpwh3OT11JJl&signin%24UserName=test&signin%24UserPass=test&signin%24Button1.x=42&signin%24Button1.y=17 

編輯3

變化

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

感謝

:)

+0

謝謝巴巴,你能告訴我如何實現你在C中描述的參數嗎? – KiloJKilo 2012-04-03 00:47:03

+0

以及您如何確定這些參數是必需的? – KiloJKilo 2012-04-03 00:54:39

+0

這就是當你點擊提交 – Baba 2012-04-03 00:56:22

1

您將需要使用與美元符號的表單字段名稱;您需要轉義$,以便它不被解釋爲變量,或者將其粘貼在單引號中,因此僅以純文本形式評估。

$post = 'signin$UserName=' . $username . '&signin$UserPass=' . $password; 
// or 
$post = "signin\$UserName=$username&signin\$UserPass=$password"; 

試試看看你有沒有進展。在瀏覽器中使用類似Wiresharklivehttpheaders的內容嗅探請求,以幫助您查看提交數據的確切格式。

又見PHP - Strings - Single Quoted

+0

感謝您的回覆,它幫助了我的原始問題。 :) – KiloJKilo 2012-04-03 20:36:32

0

至於我可以看到你只是你的兩個職位參數之間缺少一個符號(&)。

爲了處理輸入字段名稱中的$,只需在代碼中使用\$(轉義美元符號),或者將帶有$符號的部分放入單引號中。 (但你必須把所有的變量引用字符串外,並用.將它們連接起來)

+0

感謝您的迴應。 – KiloJKilo 2012-04-03 20:36:48