note 104369 modified in function.curl-setopt-array by danbrown

From: Date: Sat, 11 Jun 2011 15:34:10 +0000
Subject: note 104369 modified in function.curl-setopt-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180440@lists.php.net to get a copy of this message
it should be noted that when using CURLOPT_POSTFIELDS in a loop, CURLOPT_POSTFIELDS appends to the sting. You can use unset() if you don't want this sort of behavior. <?php //this will append postfields while(true) { $options = array(CURLOPT_POSTFIELDS => 'foo=bar&foo2=bar'); $ch = curl_init("http://www.example.com"); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); } //this will NOT append postfields while(true) { $options = array(CURLOPT_POSTFIELDS => 'foo=bar&foo2=bar'); $ch = curl_init("http://www.example.com"); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); unset($options[CURLOPT_POSTFIELDS]); } ?> --was-- it should be noted that when using CURLOPT_POSTFIELDS in a loop, CURLOPT_POSTFIELDS appends to the sting. You can use unset() if you don't want this sort of behavior. <?php //this will append postfields while(true) { $options = array(CURLOPT_POSTFIELDS => 'foo=bar&foo2=bar'); $ch = curl_init("http://www.example.com"); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); } //this will NOT append postfields while(true) { $options = array(CURLOPT_POSTFIELDS => 'foo=bar&foo2=bar'); $ch = curl_init("http://www.example.com"); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); unset($options[CURLOPT_POSTFIELDS]); } http://php.net/manual/en/function.curl-setopt-array.php

« previous php.notes (#180440) next »