简体   繁体   中英

php cURL script run twice

I have a tragedic issue, with my curl, i want to post one time and my action is executed twice.

I don't have two curl_exec() or is not a html output problem, and i have aldready search to my best friend Google, and to other post on stackoverflow. My request is send successfully, but the last problem is that ...

My config

      CURLOPT_URL            => $url,
      CURLOPT_RETURNTRANSFER => false,      
      CURLOPT_HEADER         => false,      
      CURLOPT_FAILONERROR    => true,      
      CURLOPT_POST           => true,       
      CURLOPT_POSTFIELDS     => $postFields, 
      CURLOPT_VERBOSE        => true,
      CURLOPT_SSL_VERIFYPEER => 0,
      CURLOPT_SSL_VERIFYHOST => 0,
      CURLOPT_PROTOCOLS      =>  CURLPROTO_HTTP,
      CURLOPT_USERAGENT      => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'

$CURL=curl_init();

if(empty($CURL)){die("ERREUR");}
       curl_setopt_array($CURL,$options);

      curl_exec($CURL);

        curl_close($CURL);  

      $content = ob_get_contents();
      ob_end_clean();

      if(curl_errno($CURL)){
            echo "ERREUR curl_exec : ".curl_error($CURL); 
      }

      ob_end_flush();


echo $content;

Have you any idea to resolve that, thanks.

Your curl only executes once but outputs twice. The first one comes from curl_exec($CURL) , because CURLOPT_RETURNTRANSFER is false,

TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. curl_setopt

The second one is obviously from echo $content;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM