Index: core/units/helpers/curl_helper.php =================================================================== --- core/units/helpers/curl_helper.php +++ core/units/helpers/curl_helper.php @@ -148,6 +148,11 @@ parent::__construct(); $this->debugMode = kUtil::constOn('DBG_CURL'); + + // Happens, when cURL binding version is below v7.18.2. + if ( !defined('CURLINFO_REDIRECT_URL') ) { + define('CURLINFO_REDIRECT_URL', 1048607); + } } /** @@ -494,6 +499,20 @@ return $this->lastRedirectCount; } + if ( $info_type == CURLINFO_REDIRECT_URL ) { + if ( $this->followLocation ) { + return ''; + } + + foreach ( $this->responseHeaders as $header ) { + if ( preg_match('/^location: (.*)$/i', $header, $matches) ) { + return $matches[1]; + } + } + + return ''; + } + return curl_getinfo($this->connectionID, $info_type); } @@ -570,4 +589,4 @@ return ($this->lastHTTPCode == 200) || ($this->lastHTTPCode >= 300 && $this->lastHTTPCode < 310); } - } \ No newline at end of file + } Index: index.php =================================================================== --- index.php +++ index.php @@ -19,7 +19,24 @@ $application =& kApplication::Instance(); $application->Init(); -$application->Run(); + +/** @var kCurlHelper $curl_helper */ +$curl_helper = $application->recallObject('CurlHelper'); + + +$curl_helper->followLocation = false; +$curl_helper->Send('http://www.google.com', false); +echo 'Redirect URL (not following): [' . $curl_helper->getInfo(CURLINFO_REDIRECT_URL) . ']' . PHP_EOL; +echo 'Effective URL (not following): [' . $curl_helper->getInfo(CURLINFO_EFFECTIVE_URL) . ']' . PHP_EOL; +$curl_helper->CloseConnection(); + +$curl_helper->followLocation = true; +$curl_helper->Send('http://www.google.com', false); +echo 'Redirect URL (following): [' . $curl_helper->getInfo(CURLINFO_REDIRECT_URL) . ']' . PHP_EOL; +echo 'Effective URL (following): [' . $curl_helper->getInfo(CURLINFO_EFFECTIVE_URL) . ']' . PHP_EOL; +$curl_helper->CloseConnection(); + +// $application->Run(); $application->Done(); -$end = microtime(true); \ No newline at end of file +$end = microtime(true);