Controlling curl output in php

How to hide output from curl in PHP?

My code in its current form is as follows:

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERPWD, PSSWDINFO); $result= curl_exec ($ch); curl_close ($ch); 

The problem is that it displays the whole page, how can I just show a message about success or failure?

+54
php curl
Aug 05 '09 at 17:08
source share
2 answers

Use this parameter for curl_setopt() :

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

This will cause curl_exec return data instead of output.

To find out if this is successful, you can check $result as well as curl_error() .

+150
Aug 05 '09 at 17:10
source share

Also disable this option:

 curl_setopt($ch, CURLOPT_VERBOSE, 0); 

Or else he will still print everything on the screen.

+8
Sep 12 '14 at 19:40
source share



All Articles