trinvh2 / php5rp

A PHP Reverse Proxy
0 stars 0 forks source link

Array $_POST variables #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When an array of variables is used in a form like this:
<form>
<input name='inptest[1]'></input>
<input name='inptest[2]'></input>
</form>
php interprets the array itself. With this code in the form post data
encoding part this problem is solved:

// Encode and form the post data
foreach($_POST as $key=>$value)
{
  if (is_array($value)) {
    foreach($value as $idx=>$val) {
      $post[] = urlencode($key.'['.$idx.']')."=".urlencode($val);
    }
  } else {
    $post[] = urlencode($key)."=".urlencode($value);
  }
}

Original issue reported on code.google.com by kristof....@gmail.com on 3 Mar 2008 at 5:44

GoogleCodeExporter commented 9 years ago
This works even better:

if (!isset($HTTP_RAW_POST_DATA))
  $HTTP_RAW_POST_DATA = file_get_contents("php://input"); 
$this->setCurlOption(CURLOPT_POSTFIELDS, $HTTP_RAW_POST_DATA);

Original comment by kristof....@gmail.com on 4 Mar 2008 at 9:02