Handling Headers

CURLOPT_HEADER holds a boolean flag that, when set to true, will cause headers to be included in the response string returned by cu rl_exec.

Another option for getting at some of the data included in the response headers, such as the HTTP response code, is to use the curl_getinfo function as shown in the following example. For more on what other information this function offers, see its entry in the PHP manual.

<?php
$ch = curl_init();
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE); ?>

CURLOPT_HTTPHEADER holds an enumerated array of custom request header name-value pairs formatted like so.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept-Language: en-us,en;q=0.5', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Keep-Alive: 300',
'Connection: keep-alive'
));
?>

© cURL Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (30.08.2014)
Views: 351 | Rating: 0.0/0
Total comments: 0
avatar