$value) { $param = str_replace("%7E", "~", rawurlencode($param)); $value = str_replace("%7E", "~", rawurlencode($value)); $canonicalized_query[] = $param."=".$value; } $canonicalized_query = implode("&", $canonicalized_query); $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query; /* calculate the signature using HMAC with SHA256 and base64-encoding. The 'hash_hmac' function is only available from PHP 5 >= 5.1.2. */ $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True)); /* encode the signature for the request */ $signature = str_replace("%7E", "~", rawurlencode($signature)); /* create request */ $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature; /* I prefer using CURL */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $xml_response = curl_exec($ch); /* If cURL doesn't work for you, then use the 'file_get_contents' function as given below. */ if ($xml_response === False) { return False; } else { /* parse XML */ $parsed_xml = @simplexml_load_string($xml_response); return ($parsed_xml === False) ? False : $parsed_xml; } } ?>