2010-08-29 124 views
1

我有問題,我正在嘗試使用php和cURL發佈數據,但這不起作用。cURL如何正確發佈此表單?

應該如何正確查找代碼,如果形式是通過輸入值隨機會話ID安全,並有發佈(臺)件

  <form name='p' method='post' action='/pl/Register.php'> 
     <input type='hidden' name='sid' value='wa12891300kv1283056988qwpvkdaazzipdgouxd'> 
     <input type='hidden' name='stage' value='20'> <!-- this value change when post some "values" --> 
     <input type='hidden' name='addressline1' value=''> 
     <input type='hidden' name='addressline2' value=''> 
     <input type='hidden' name='addressline3' value=''> 

     <input type='hidden' name='addressline4' value=''> 
     <input type='hidden' name='postcode' value=''> 
     <input type='hidden' name='bankname' value=''> 
     <input type='hidden' name='sortcode' value=''> 
     <input type='hidden' name='accountname' value=''> 
     <input type='hidden' name='accountnumber' value=''> 
     <input type='hidden' name='cardname' value=''> 
     <input type='hidden' name='cardtype' value=''> 
     <input type='hidden' name='cardnumber' value=''> 

     <input type='hidden' name='startmonth' value=''> 
     <input type='hidden' name='startyear' value=''> 
     <input type='hidden' name='expirymonth' value=''> 
     <input type='hidden' name='expiryyear' value=''> 
     <input type='hidden' name='cardsecurity' value=''> 
     <input type='hidden' name='cardissue' value=''> 
     <input type='hidden' name='delname' value=''> 
     <input type='hidden' name='deladdressline1' value=''> 
     <input type='hidden' name='deladdressline2' value=''> 

     <input type='hidden' name='deladdressline3' value=''> 
     <input type='hidden' name='deladdressline4' value=''> 
     <input type='hidden' name='delpostcode' value=''> 
     <input type='hidden' name='delphone' value=''> 
     <input type='hidden' name='sponsor' value=''> 
     <input type='hidden' name='uid' value=''> 
     <input type='hidden' name='password' value=''> 
     <input type='hidden' name='password1' value=''> 
     <input type='hidden' name='password2' value=''> 

     <input type='hidden' name='terms1' value='0'> 
     <input type='hidden' name='terms2' value='0'> 

任何幫助將受到歡迎。

+0

你的PHP看起來像什麼?此外,它可以幫助你簡化你的例子....也許只向我們展示一個2或3行表單(也關閉你的表單)。 – 2010-08-29 04:54:07

回答

0

您向我們展示了一個HTML表單。你的PHP腳本是/pl/Register.php?你究竟想要發佈什麼內容,從哪裏到哪裏?

PHP運行服務器端,而不是客戶端。 PHP不會在瀏覽器中運行,因此您無法使用瀏覽器中的PHP發佈表單。你只能用Javascript做到這一點......或者更好,只是一個提交按鈕將在這種情況下。

+0

我正在嘗試發佈個人數據(如出生日期,家庭住址等)。不幸的是,我不知道PHP原始網站http://www.betterware.eu/pl/Register.php究竟是什麼樣子,但我的代碼是http://pastebin.com/LPHVuxKB – ramadan 2010-08-29 12:06:29

0

有兩個部分:

  • 獲得sid值。
  • 發送包含sid值和其他數據的請求。

首先我們得到sid。我不太瞭解你請求表單時會發生什麼,但如果它只是每次訪問頁面時分配的隨機數,那麼你可以在你的php腳本中獲取頁面並搜索它的值。我們可以做到這一點簡單地使用file_get_contents和正則表達式:

$remote_site = file_get_contents("http://example.com/pl/Register.php"); 
    if (preg_match('/name=\'sid\' value=\'(.+?)\'/', $remote_site, $match)) { 
      $sid = $match[1]; 
    } else { 
      exit('failed to find sid'); 
    } 

現在我們只需要使用捲曲發送POST請求。您需要從您要提交的表單中提取所有數據。

我建議把它在一個關聯數組:

$post_data = array(
      'sid' => $sid, 
      'stage' => '...', 
    ); 

我會讓你來填寫休息。

爲了發表它,你想用CURLOPT_POSTCURLOPT_POSTFIELDS如下送與捲曲, POST請求:

$ch = curl_init("http://example.com/pl/Register.php"); 
    curl_setopt($ch, CURLOPT_POST, true); // tell cURL we are doing a post request 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // we pass in our data as an array here 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // this stops the output from being printed directly 
    $response = curl_exec($ch); 

然後,您可以讀取$response看到請求的結果。 *

+0

像我寫了bellow我的代碼是在這裏,http://pastebin.com/LPHVuxKB 問題得到「sid」值我已刪除,但現在我有發佈的問題這個。這對我來說很難,因爲在90階段我必須「得到迴應」,並獲得價值的內容併發布。也許如果你在http://www.betterware.eu/pl/Register.php看到表單,你可以簡單地說一些新的東西。但我會嘗試捕獲響應形式curl_exec($ ch);和preg_match獲取uid值 – ramadan 2010-08-29 12:12:25