3 function tool_mfs_HTTPOpen($url)
7 $url = "http://su1:50000/admin.php";
9 $uri_params = 'user_login=support';
10 $uri_params .= '&shard=103';
11 $uri_params .= '&forum=Atrium Keepers';
13 curl_setopt($ch, CURLOPT_URL
, $url);
14 curl_setopt($ch, CURLOPT_POST
, 1);
15 curl_setopt($ch, CURLOPT_POSTFIELDS
, $uri_params);
16 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1); // 0 = debug , 1 = normal
17 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1); // 0 = debug , 1 = normal
18 curl_setopt($ch, CURLOPT_NOPROGRESS
, 0);
19 curl_setopt($ch, CURLOPT_USERAGENT
, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
20 curl_setopt($ch, CURLOPT_HEADER
, 1); // has to be 1 due to using redirections
21 curl_setopt($ch, CURLOPT_TIMEOUT
, 120);
24 $curlOutput = curl_exec ($ch);
27 $curlError = curl_errno($ch);
30 $outp = "CURL Error [ $curlError ] : ". curl_error($ch);
34 $curlData = tool_mfs_HTTPParseResponse($curlOutput);
44 function tool_mfs_HTTPParseResponse($response)
47 returns an array in the following format which varies depending on headers returned
49 [0] => the HTTP error or response code such as 404
52 [Date] => Wed, 28 Apr 2004 23:29:20 GMT
53 [Set-Cookie] => COOKIESTUFF
54 [Expires] => Thu, 01 Dec 1994 16:00:00 GMT
55 [Content-Type] => text/html
57 [2] => Response body (string)
62 list($response_headers,$response) = explode("\r\n\r\n",$response,2);
63 $response_header_lines = explode("\r\n",$response_headers);
65 // first line of headers is the HTTP response code
66 $http_response_line = array_shift($response_header_lines);
67 if (preg_match('@^HTTP/[0-9]\.[0-9] ([0-9]{3})@',$http_response_line, $matches))
69 $response_code = $matches[1];
73 $response_code = "Error";
76 while ((substr($response_code, 0,1) == "1") ||
(substr($response_code, 0,1) == "3"));
78 $response_body = $response;
80 // put the rest of the headers in an array
81 $response_header_array = array();
82 foreach ($response_header_lines as $header_line)
84 list($header,$value) = explode(': ',$header_line,2);
85 $response_header_array[$header] = $value;
88 return array($response_code,$response_header_array,$response_body);