March 22, 2011, 9:47 p.m.
posted by stackme
Fetching a URL with Arbitrary Headers
Set the header stream context option when using the http stream as in Figure. The header value must be a single string. Separate multiple headers with a carriage return and newline (\r\n inside a double-quoted string).
Sending a header with the http stream
With cURL, set the CURLOPT_HTTPHEADER option to an array of headers to send, as shown in Figure.
Sending a header with cURL
With HTTP_Request, use the addHeader( ) method, as shown in Figure.
Sending a header with HTTP_Request
cURL has special options for setting the Referer and User-Agent request headers'CURLOPT_REFERER and CURLOPT_USERAGENT. Figure uses each of these options.
Setting Referer and User-Agent with cURL
Documentation on on the http stream wrapper at http://www.php.net/wrappers.http, on curl_setopt( ) at http://www.php.net/curl-setopt, and on the PEAR HTTP_Request class at http://pear.php.net/package/HTTP_Request. The mailing-list message at http://lists.w3.org/Archives/Public/ietf-http-wg-old/1996MayAug/0734.html explains the ambitious and revolutionary goals behind spelling "Referer" with one "r."