Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove HTTP headers from CURL response?
    primarykey
    data
    text
    <p>I have a php script that returns just plain text <strong>without</strong> any html. Now I want to make a cURL request to that script and I get the following response:</p> <pre><code>HTTP/1.1 200 OK Date: Mon, 28 Feb 2011 14:21:51 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.2.12-nmm2 Vary: Accept-Encoding Content-Length: 6 Content-Type: text/html 6.8320 </code></pre> <p>The actuall response is just <strong>6.8320</strong> as text without any html. I want to retrieve it from the response above by just removing the header information.</p> <p>I already minified the script a bit:</p> <pre><code>$url = $_GET['url']; if ( !$url ) { // Passed url not specified. $contents = 'ERROR: url not specified'; $status = array( 'http_code' =&gt; 'ERROR' ); } else if ( !preg_match( $valid_url_regex, $url ) ) { // Passed url doesn't match $valid_url_regex. $contents = 'ERROR: invalid url'; $status = array( 'http_code' =&gt; 'ERROR' ); } else { $ch = curl_init( $url ); if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) { curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $_POST ); } curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_HEADER, true ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_USERAGENT, $_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] ); list( $header, $contents ) = preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $ch ), 2 ); $status = curl_getinfo( $ch ); curl_close( $ch ); } // Split header text into an array. $header_text = preg_split( '/[\r\n]+/', $header ); if ( true ) { if ( !$enable_native ) { $contents = 'ERROR: invalid mode'; $status = array( 'http_code' =&gt; 'ERROR' ); } // Propagate headers to response. foreach ( $header_text as $header ) { if ( preg_match( '/^(?:Content-Type|Content-Language|Set-Cookie):/i', $header ) ) { header( $header ); } } print $contents; } </code></pre> <p>Any idea what I need to change to remove the header information from the response?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload