PHP cURL Double Submission When Fields Array Printed

I'm using cURL to submit a form on another webpage and have ran into a weird phenomenon:

When I use print_r($fields) to print out the post fields BEFORE I pass the array to cURL request and submit it, the form is submitted twice. When I remove that line from the script, the double submission disappears.

Why is printing the array causing a double submission?

//set POST variables
$fields = array();
$fields['input-name'] = 'input-value';

print_r($fields); //causes double submission

//open connection
$url = '';
$request = curl_init($url);

//send post data
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $fields);

// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($request);

0 Comment



Captcha image