for beinners, please check this example on how to use curl library.
to include headers in response, set CURLOPT_HEADER to 1 in curl options. ie,
PHP:
curl_setopt_array($c, array( | |
... | |
CURLOPT_HEADER => 1, | |
... | |
)); |
to include headers only in response, set CURLOPT_CUSTOMREQUEST to 'HEAD' in curl options. ie,
PHP:
curl_setopt_array($c, array( | |
... | |
CURLOPT_CUSTOMREQUEST=> 'HEAD', | |
... | |
)); |
when response returned, header and body are separated with "\r\n\r\n". make sure double quotes are used.
the following code with extract headers and body from curl response, even if the above response is not set.
PHP:
$response = curl_exec($c); | |
if (strpos($response, "\r\n\r\n") > 0) // has header | |
list($header, $body) = explode("\r\n\r\n", $response); | |
else | |
$body = $response; |
line 2: if header separator exists in the response, it has a header.
lines 2 and 3: make sure double quotes are used!
important! this assumes that the body of response does not include the header separator string. you may wish to enhance the code by checking header size (by calling curl_getinfo()).