Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

managing curl output in php

Tags:

php

curl

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?

like image 646
mrpatg Avatar asked Aug 05 '09 17:08

mrpatg


People also ask

What does PHP cURL return?

Functions of cURL in PHP curl_error — It will return the string which represents the error for the particular current session.


1 Answers

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().

like image 142
Greg Avatar answered Oct 25 '22 11:10

Greg