Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions libraries/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '')
{
Expand Down Expand Up @@ -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'))
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -376,4 +394,4 @@ public function set_defaults()
}

/* End of file Curl.php */
/* Location: ./application/libraries/Curl.php */
/* Location: ./application/libraries/Curl.php */