$header = $this->parseHeader(substr($output, 0, $header_size)); $body = substr($output, $header_size); curl_close($ch); //Print the response header var_dump($header); /* If we get any of this X-GGe4-Content-SHA1 X-GGe4-Date Authorization * then the API call is valid */ if (isset($header['authorization'])) { //Ovbiously before we do anything we should validate the hash var_dump(json_decode($body)); } else { echo $body; } } private function parseHeader($rawHeader) { $header = array(); //http://blog.motane.lu/2009/02/16/exploding-new-lines-in-php/ $lines = preg_split('/\\r\\n|\\r|\\n/', $rawHeader); foreach ($lines as $key => $line) { $keyval = explode(': ', $line, 2); if (isset($keyval[0]) && isset($keyval[1])) { $header[strtolower($keyval[0])] = $keyval[1]; } } return $header; } } $firstdata = new FirstData(); $firstdata->request();