2012-12-02 40 views
0

我試圖登錄到它具有以下形式的網站:PHP的捲曲發送信息,以滿足隱藏輸入

<div class="inner"> 
     <form name="loginform" action="/site/?module=account&action=login&return_url=" method="post"> 
     <input type="hidden" name="server" value="nice"> 
     <div class="inputs"> 
      <div class="user"> 
       <input style="width: 108px;" id="login_user" type="text" name="username" value="username" onfocus="inputFocus(this)" onblur="inputBlur(this)" /> 
      </div> 
      <div class="pass"> 
       <input style="width: 108px;" id="login_pass" type="password" name="password" value="password" onfocus="inputFocus(this)" onblur="inputBlur(this)" /> 
       <input type="submit" style="visibility:hidden"/> 
      </div> 
     </div> 
     <div class="submit"> 
      <div class="submit-btn" onclick="document.loginform.submit();"></div> 
     </div> 
     <div class="clear"></div> 
     <div class="links"> 
      <a href="/site/?module=account&action=resetpass">Forgot Password?</a> 
     </div> 
    </form> 

</div> 

使用這個PHP腳本:

<?php 
$username=""; 
$password=""; 
$url="(handled this)"; 
$cookie="cookie.txt"; 

$postdata = "username=".$username."&password=".$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); 

?> 

將輸出:

Invalid login server selected, please try again with a valid server. 

因爲我沒有滿足隱藏的輸入。 我試圖在谷歌搜索,但我看不到一個PHP腳本,應該爲此工作。 對不起,我在課堂上沒有教過cURL。

+0

如果這只是一個不發送隱藏字段數據的問題......那麼爲什麼不直接發送呢?你已經有了用戶名和密碼。 –

回答

0

將服務器添加到您的$ postdata。

​​

順便說一句:你需要urlencode參數名稱和參數值。

+0

我怎樣才能使用cURL來做到這一點? – Mowgli