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 = 'http://blah.com/blah/blah';
$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);
CURLOPT_RETURNTRANSFERto TRUE, only to echo the return yourself? I searched your problem, and changing this helped in some ocasions. (no explanation to the double submital) php curl script run twice when printing return stringprint_rdoesn't affect your form submission for short.curl_exec"Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure. " So an echo still seems necessary, and it's not printing my results twice. Thanks for looking that up! However, I already ran across that one. The only thing that has fixed my double submission issue is removingprint_r($fields);.