diff --git a/libraries/Curl.php b/libraries/Curl.php index c53ae48..f8f4997 100644 --- a/libraries/Curl.php +++ b/libraries/Curl.php @@ -23,6 +23,7 @@ class Curl { public $error_code; // Error code returned as an int public $error_string; // Error message returned as a string public $info; // Returned after request (elapsed time, etc) + public $response_headers; // Array containing all response headers function __construct($url = '') { @@ -281,6 +282,10 @@ public function execute() { $this->options[CURLOPT_FAILONERROR] = TRUE; } + if ( ! isset($this->options[CURLOPT_HEADER])) + { + $this->options[CURLOPT_HEADER] = TRUE; + } // Only set follow location if not running securely if ( ! ini_get('safe_mode') && ! ini_get('open_basedir')) @@ -302,6 +307,19 @@ public function execute() // Execute the request & and hide all output $this->response = curl_exec($this->session); $this->info = curl_getinfo($this->session); + $this->response_headers = explode("\r\n\r\n", $this->response, $this->info['redirect_count'] + 2); + $this->body = array_pop($this->response_headers); + foreach ($this->response_headers as $redirect => $headers) + { + $headers = explode("\r\n", $headers); + $this->response_headers[$redirect] = array(); + $this->response_headers[$redirect]['Status'] = array_shift($headers); + foreach ($headers as $header_line) + { + list($key, $value) = explode(':', $header_line, 2); + $this->response_headers[$redirect][$key] = trim($value); + } + } // Request failed if ($this->response === FALSE) @@ -322,7 +340,7 @@ public function execute() else { curl_close($this->session); - $this->last_response = $this->response; + $this->last_response = $this->body; $this->set_defaults(); return $this->last_response; } @@ -376,4 +394,4 @@ public function set_defaults() } /* End of file Curl.php */ -/* Location: ./application/libraries/Curl.php */ \ No newline at end of file +/* Location: ./application/libraries/Curl.php */