PHP Cookbook: Solutions and Examples for PHP Programmers
13.4.1. Problem
You want to retrieve a URL that requires specific headers to be sent with the request for the page. 13.4.2. Solution
Set the header stream context option when using the http stream as in Example 13-20. 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 Example 13-22. Sending a header with cURL
With HTTP_Request, use the addHeader( ) method, as shown in Example 13-35. Sending a header with HTTP_Request
13.4.3. Discussion
cURL has special options for setting the Referer and User-Agent request headers'CURLOPT_REFERER and CURLOPT_USERAGENT. Example 13-23 uses each of these options. Setting Referer and User-Agent with cURL
13.4.4. See Also
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." |
Категории