Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL and PHP: Stop output to screen

This PHP script prints all the data minus the XML to the browser (I'm using Chrome). How can I suppress output to screen?

<html> <head><title>Twitcap</title></head> <body> <?php   function twitcap()   {     // Set your username and password     $user = 'osoleve';     $pass = '********';      $ch = curl_init("https://twitter.com/statuses/friends_timeline.xml");      curl_setopt($ch,CURLOPT_HEADER,0); // We want to see the header     curl_setopt($ch,CURLOPT_TIMEOUT,30); // Set timeout to 30s     curl_setopt($ch,CURLOPT_USERPWD,$user.':'.$pass); // Set uname/pass     curl_setopt($ch,CURLOPT_RETURNTRANSER,1); // Do not send to screen      curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);     curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);      $xml = new SimpleXMLElement( curl_exec($ch) );     curl_close($ch);      return $xml;   }    $content = twitcap();   echo "Hello, world.<br /><br />"; ?> </body> </html> 
like image 971
Oso Avatar asked Aug 08 '10 18:08

Oso


People also ask

How do I get my printer to stop curling?

The procedure to hide curl progress bar is to pass the -s or --silent option to the curl command: Open the terminal application on your Linux/Unix. Type the command (pass -s option to curl to hide progress bar): $ curl -s https://your-dot-com-domain-name-here/ > /tmp/output. html.

Does curl work in PHP?

cURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains. Obtaining a copy of a website's material. Submission of forms automatically, authentication and cookie use.

How does PHP handle curl request?

curl_setopt( $curl , CURLOPT_POSTFIELDS, $json_string ); curl_setopt( $curl , CURLOPT_HTTPHEADER, array ( 'Content-Type:application/json' )); curl_setopt( $curl , CURLOPT_RETURNTRANSFER, true ); $data = curl_exec( $curl );

How let curl use same cookie as browser in PHP?

You can't. The only way this would work is if you use persistent cookies in your curl request. CURL can keep cookies itself. Assign a session ID to the cookie file (in curl) so subsequent requests get the same cookies.


1 Answers

You ommitted the F in TRANSFER, change this:

curl_setopt($ch,CURLOPT_RETURNTRANSER,1);

To this: CURLOPT_RETURNTRANS F ER

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

like image 74
Brandon Horsley Avatar answered Oct 03 '22 18:10

Brandon Horsley