From 17e4e31dd7f5b943d6d23f4ccde01d3214a52ff9 Mon Sep 17 00:00:00 2001 From: Christian Helbling Date: Wed, 15 Jun 2011 07:28:07 +0000 Subject: added custom headers to get_multi --- it_url.class | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'it_url.class') diff --git a/it_url.class b/it_url.class index aa4f985..91dae20 100644 --- a/it_url.class +++ b/it_url.class @@ -351,12 +351,19 @@ function get($p=null, $timeout=5) * @param $p['urls']: array of urls to get * @param $p['timeout']: timeout per read in seconds, defaults to 5. (TODO: fractions allowed?) * @param $p['totaltimeout']: timeout for the whole function call + * @param $p['headers']: optional array of HTTP headers to send * @return array of contents of resulting page using same keys as the urls input array, * considering redirects, excluding headers */ function get_multi($p=null) { $p += array('totaltimeout' => "999999", 'timeout' => 5, 'retries' => 1); + $p['headers'] = (array)$p['headers'] + array( + 'User-Agent' => "Mozilla/4.0 (compatible; MSIE 7.0; ITools)", + 'Accept-Language' => T_lang(), + ); + foreach ($p['headers'] as $header => $value) + $headers[] = "$header: $value"; $opts = array( CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, @@ -364,6 +371,7 @@ function get_multi($p=null) CURLOPT_LOW_SPEED_LIMIT => 5, CURLOPT_LOW_SPEED_TIME => $p['timeout'], CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTPHEADER => $headers, ); $mh = curl_multi_init(); -- cgit v1.2.3