Managing curl output in php

PhpCurl

Php Problem Overview


How do I hide the output from curl in PHP?

My code as it stands is the following:

$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 is spews out the entire page, how can I simply show a "success" or "failed" message?

Php Solutions


Solution 1 - Php

Use this option to curl_setopt():

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

This will make curl_exec return the data instead of outputting it.

To see if it was successful you can then check $result and also curl_error().

Solution 2 - Php

Also make sure to turn off this option:

curl_setopt($ch, CURLOPT_VERBOSE, 0);       

Or else it will still print everything to screen.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmrpatgView Question on Stackoverflow
Solution 1 - PhpGregView Answer on Stackoverflow
Solution 2 - PhpEric LeschinskiView Answer on Stackoverflow