cURL / Mailing Lists / curl-and-php / Single Mail


Getting the http headers into a separate variable

From: Kenneth Andresen <>
Date: Fri, 21 Jul 2006 21:22:37 -0500

Hello all,

I am trying to obtain both the header data and the content of a curl
request using the following function:

    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HEADER,1);
    $result = curl_exec ($curl);
    curl_close ($curl);
    print $result;

The CURLOPT_HEADER writes the header as part of the regular output. I
believe an alternative CURLOPT_WRITEHEADER can write to file, for then
reading the file again, however I would assume there must be a way to
get the data right into a variable. What is the best way for doing this?

Best regards,

Received on 2006-07-22